Skip to content

Instantly share code, notes, and snippets.

@tezvi
Last active July 3, 2017 17:50
Show Gist options
  • Save tezvi/350ba75532ff2a89f7cb8d4fa5d95b8f to your computer and use it in GitHub Desktop.
Save tezvi/350ba75532ff2a89f7cb8d4fa5d95b8f to your computer and use it in GitHub Desktop.
Output unique banned IP addresses from fail2ban service log file
#!/bin/bash
# output unique ip addresses banned by fail2log
grep "Ban " /var/log/fail2ban.log \
| grep `date -d "1 day ago" +%Y-%m-%d` \
| awk '{print $NF " ("$NF") "$6""}' \
| sort \
| uniq -c \
| awk '{print $2" "$3" "$4" "$1}' \
| logresolve \
| awk '{print $4" "$1" "$2" "$3}' \
| sort -rn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment