Skip to content

Instantly share code, notes, and snippets.

@indradhanush
Forked from nega0/iptables_color.txt
Created August 8, 2018 07:29
Show Gist options
  • Save indradhanush/5d81af4650ec6d623f741a85a49b1e9d to your computer and use it in GitHub Desktop.
Save indradhanush/5d81af4650ec6d623f741a85a49b1e9d to your computer and use it in GitHub Desktop.
colorize your `iptables` output
## based on the blogpost here: http://blog.sjas.de/posts/colored-iptables-output.html
iptables --line-numbers -vnL |\
sed -E 's/^Chain.*$/\x1b[4m&\x1b[0m/' |\
sed -E 's/^num.*/\x1b[33m&\x1b[0m/' |\
sed -E '/([^y] )((REJECT|DROP))/s//\1\x1b[31m\3\x1b[0m/' |\
sed -E '/([^y] )(ACCEPT)/s//\1\x1b[32m\2\x1b[0m/' |\
sed -E '/([ds]pt[s]?:)([[:digit:]]+(:[[:digit:]]+)?)/s//\1\x1b[33;1m\2\x1b[0m/' |\
sed -E '/([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(\/([[:digit:]]){1,3}){0,1}/s//\x1b[36;1m&\x1b[0m/g' |\
sed -E '/([^n] )(LOGDROP)/s//\1\x1b[33;1m\2\x1b[0m/'|\
sed -E 's/ LOG /\x1b[36;1m&\x1b[0m/'
## Line 4 underlines chain "section titles"
## Line 5 makes the column headers yellow
## Line 6 highlights REJECT and DROP as red everwhere except chain "section titles"
## Line 7 highlights ACCEPT as green
## Line 8 highlights port numbers as yellow
## Line 9 highlights IP address and CIDR blocks as cyan
## Line 10 highlights LOGDROP as yellow everywhere except chain "section titles"
## Line 11 highlights LOG everywhere as cyan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment