Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Last active December 11, 2015 17:48
Show Gist options
  • Select an option

  • Save stefanocudini/4636756 to your computer and use it in GitHub Desktop.

Select an option

Save stefanocudini/4636756 to your computer and use it in GitHub Desktop.
add ignorep in all fail2ban jails
#!/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