Created
February 11, 2024 13:47
-
-
Save gqqnbig/ed590fa53fbb12ff986f2d6de1ea784a to your computer and use it in GitHub Desktop.
Add block count to ufw status report
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
#!/bin/awk | |
{ | |
ORS="" | |
print $0 | |
if ($2 == "DENY" && $3 ~ /\.0\/24$/ && $4 == "(log)") { | |
subnet=substr($3, 0,length($3)-4) | |
print "\t\t" | |
#print subnet | |
print "grep -F " subnet " /var/log/ufw.* | wc -l\n" | "/bin/bash" | |
# If we don't close bash, the output of bash will not flush to the stdout, | |
# so the order will be wrong. | |
close("/bin/bash") | |
# Unfortunately, `wc` outputs newline character. | |
} | |
else { | |
print "\n" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This AWK program counts the number of times an IP is blocked (and logged) by UFW.
It assumes the src format ends with ".0/24".
It's tested on Ubuntu 20.
Usage