User Tools

Site Tools


pages:scripts:fail2ban-removeban

fail2ban-removeban

fail2ban-removeban
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Fail2ban IP Remove Ban / Unban Script
# Version 2.0
# 03 September 2015
# Copyright (c) Adrian Jon Kriel : root-at-extremecooling-dot-org
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
####################
#
# Remove Ban / Unban an IP from all Fail2ban Jails
# Usage: fail2ban-remove-ban.sh <ip-address-to-unban>
#
# Remove Ban of multiple IP addresses
# Usage: fail2ban-remove-ban.sh <ip-1> <ip-2> <ip-3>
#
####################
if [[ ! "$1" ]]; then
    echo "Usage: ${0##*/} <ip-address-to-unban>";
    echo "Multiple IP: ${0##*/} <ip1> <ip2> <ip3> <ip4>";
    exit
fi
 
for var in "$@"
do
    if [[ $var =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
        JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
        for JAIL in $JAILS
        do
          RESULT=`fail2ban-client set $JAIL unbanip $var 2>&1`
 
          if [[ "$RESULT" == *"NOK"* ]]; then
            echo "$var NOT banned in $JAIL";
          else
             echo "Removed $var ban from $JAIL"
          fi
        done
    else
        echo "ERROR: invalid IP $var";
 
    fi
done

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
pages/scripts/fail2ban-removeban.txt · Last modified: 2022/12/31 00:29 by mischerh