diff --git a/fail2ban/server/actions.py b/fail2ban/server/actions.py index b052d342..74e2a615 100644 --- a/fail2ban/server/actions.py +++ b/fail2ban/server/actions.py @@ -274,6 +274,13 @@ class Actions(JailThread, Mapping): if missed: raise ValueError("not banned: %r" % missed) return cnt + # IPs can be represented in string format (e.g.: tuples) + is_ip_parsed = True + if isinstance(ip, str): + try: + ip = eval(ip) + except Exception: + is_ip_parsed = False # Single IP: # Always delete ip from database (also if currently not banned) if db and self._jail.database is not None: @@ -285,14 +292,14 @@ class Actions(JailThread, Mapping): self.__unBan(ticket) else: # Multiple IPs by subnet or dns: - if not isinstance(ip, IPAddr): + if not is_ip_parsed and not isinstance(ip, IPAddr): ipa = IPAddr(ip) if not ipa.isSingle: # subnet (mask/cidr) or raw (may be dns/hostname): ips = list(filter(ipa.contains, self.banManager.getBanList())) if ips: return self.removeBannedIP(ips, db, ifexists) # not found: - msg = "%s is not banned" % ip + msg = "%s is not banned" % str(ip) logSys.log(logging.MSG, msg) if ifexists: return 0