#!/bin/bash logfile=’/var/log/fail2ban.log’ fallbackjail=’sshd’ echo “Enter ip to unban:” read ip echo “Checking whether the ip is banned” if [ 0 -lt `iptables -n -L|grep “REJECT”|grep “\”|wc -l` ] then echo “The ip $ip is banned” else echo “The ip $ip is not banned, ABORTING” exit fi echo “Trying to guess the jail name from $logfile” jail=`grep “Ban $ip$” $logfile|cut -d ‘[‘ -f 3|cut -d ‘]’ -f 1` if [ 0 -lt ${#jail} ] then echo “Found jail $jail for this ip” else echo “No jail found assuming $fallbackjail” jail=$fallbackjail fi echo “Checking that jail exists” exists=`fail2ban-client status|grep “$jail”` if [ 0 -lt ${#exists} ] then echo “Jail $jail exists” else echo “Jail $jail doesn’t exist, ABORTING” exit fi echo “Unbanning ip $ip from jail $jail” fail2ban-client set $jail unbanip $ip