Last active
August 29, 2015 14:04
-
-
Save jyotty/b5fe13711acf705f2cf6 to your computer and use it in GitHub Desktop.
show iptables rules clearly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
set -o pipefail | |
BOLD="$(printf "\x1B[1m")" | |
CLEAR="$(printf "\x1B[0m")" | |
ruledir="$(mktemp -d /tmp/fw.XXXXXX)" | |
trap "{ rm -f $ruledir/*; rmdir $ruledir; exit; }" EXIT | |
for ip in ip ip6; do | |
for chain in $("$ip"tables -S | grep -- -[PN] | awk '{ print $2 }'); do | |
"$ip"tables -S "$chain" | nl -v0 >> "$ruledir/$ip" | |
echo >> "$ruledir/$ip" | |
done | |
done | |
diff -W "$(tput cols)" --side-by-side "$ruledir/ip" "$ruledir/ip6" \ | |
| sed 's/ 0 -[PN]/ /g; s/ACCEPT\|DROP\|RETURN\|REJECT/'$BOLD'&'$CLEAR'/g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment