Skip to content

Instantly share code, notes, and snippets.

@dazuelos
Forked from vitaly/pfdump.sh
Last active October 19, 2023 13:13
Show Gist options
  • Save dazuelos/3978acf5c3193ce78f3217ff8c061a29 to your computer and use it in GitHub Desktop.
Save dazuelos/3978acf5c3193ce78f3217ff8c061a29 to your computer and use it in GitHub Desktop.
script to dump PF status
#!/bin/bash
# print an anchor subset (r, n or A)
function pfprint() {
# avoid trusting PATH and .
/usr/bin/sudo pfctl -a "$2" -s"$1" 2>/dev/null
}
# print a full anchor content
function pfprint_all() {
# print the anchor name on 1st line, and all content indented
local anchor=$(printf "%-40s" ${1:-"/"})
local indent=$(printf "%-40s")
(
pfprint r "$1" | sed "s,^,r ,"
pfprint n "$1" | sed "s,^,n ,"
pfprint A "$1" | sed "s,^,A ,"
) | sed -e "1s,^,${anchor}," -e "2,\$s,^,${indent},"
# recursively descend the anchors tree
for a in $(pfprint A "$1") ; do
pfprint_all "$a"
done
}
pfprint_all
@dazuelos
Copy link
Author

dazuelos commented Aug 2, 2020

Suppress repeated anchor name printing, and indented content of anchor
to make the structure of anchors tree visible.

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