Skip to content

Instantly share code, notes, and snippets.

@nega0
Last active June 14, 2024 11:24
Show Gist options
  • Save nega0/1d232622a1fa3dad176869bbfe747602 to your computer and use it in GitHub Desktop.
Save nega0/1d232622a1fa3dad176869bbfe747602 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
@nega0
Copy link
Author

nega0 commented Feb 18, 2019

--line-nu_bm_ers

should be

--line-nu_mb_ers

😳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment