Last active
December 11, 2015 17:48
-
-
Save stefanocudini/4636756 to your computer and use it in GitHub Desktop.
add ignorep in all fail2ban jails
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/bash | |
| #references: | |
| #http://www.fail2ban.org/wiki/index.php/Commands | |
| if [ -z "$1" ] | |
| then | |
| #echo "specify ip" | |
| exit 0 | |
| fi | |
| IP=$1 | |
| FC=/usr/bin/fail2ban-client | |
| #fail2ban-client reload ssh | |
| jails=$($FC status | grep 'Jail list' | cut -f3 | sed -e 's/ *//g' -e 's/\,/\n/g') | |
| #all fail2ban jails | |
| for jail in $jails | |
| do | |
| igips=$($FC get $jail ignoreip | grep - | cut -d' ' -f2 | uniq) | |
| #ignored ips for $jail | |
| addip=1 | |
| for igip in $igips | |
| do | |
| if [ "$igip" == "$IP" ] | |
| then | |
| addip=0 | |
| break | |
| fi | |
| done | |
| if [ $addip -ne 0 ] | |
| then | |
| #$FC set $jail addignoreip $IP | |
| echo "$jail addignoreip $IP" | |
| fi | |
| done | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment