Created
January 4, 2019 11:39
-
-
Save juffaz/b850a410bd7a6f8129bb1dce6663d99d to your computer and use it in GitHub Desktop.
This file contains 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
[root@test ~]# cat fail2ban-unbanall.sh | |
#!/bin/bash | |
if [ -z "$1" ] | |
then | |
fail2ban-client status | |
echo "Please choice JAIL for argument." | |
echo "Sample: ./fail2ban-unbanall.sh jail-name" | |
exit 0 | |
fi | |
JAIL=$1 | |
fail2ban-client status "$JAIL" &> /dev/null | |
if [ $? -ne 0 ]; then | |
echo bad jail. | |
exit 255 | |
fi | |
[ -e "$HOME"/f2b-backup ] || mkdir "$HOME"/f2b-backup | |
if [ -e "$HOME"/f2b-backup/"$JAIL".lst ]; then | |
echo overwrite "$JAIL".lst? y/n | |
read OVR | |
fi | |
ADDRS=$(fail2ban-client status "$JAIL" | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}') | |
[ "$OVR" != 'n' ] && echo "$ADDRS" > "$HOME"/f2b-backup/"$JAIL".lst | |
echo unbanning $(echo "$ADDRS" | wc -w) ips... | |
for ADDR in $ADDRS; do | |
fail2ban-client set "$JAIL" unbanip "$ADDR" 1> /dev/null | |
done | |
echo ByeBye Mission Complete. | |
[root@test ~]# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment