From f75c3d8a0243550b440393cab40077e74ced7da2 Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 24 Apr 2017 21:12:01 +0200 Subject: [PATCH] code review and ChangeLog entry --- ChangeLog | 2 ++ fail2ban/server/ipdns.py | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e722608..1978bf8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -69,6 +69,8 @@ TODO: implementing of options resp. other tasks from PR #1346 - `` - PTR reversed representation of IP address - `` - host name of the IP address - `` - interpolates to the corresponding filter group capture `...` + - `` - fully-qualified name of host (the same as `$(hostname -f)`) + - `` - short hostname (the same as `$(uname -n)`) * Allow to use filter options by `fail2ban-regex`, example: fail2ban-regex text.log "sshd[mode=aggressive]" * Samples test case factory extended with filter options - dict in JSON to control diff --git a/fail2ban/server/ipdns.py b/fail2ban/server/ipdns.py index e1aa1920..567a7f7d 100644 --- a/fail2ban/server/ipdns.py +++ b/fail2ban/server/ipdns.py @@ -148,11 +148,8 @@ class DNSUtils: # get it using different ways (a set with names of localhost, hostname, fully qualified): if names is None: names = set(['localhost']) - for hostname in (socket.gethostname, socket.getfqdn): - try: - names |= set([hostname()]) - except Exception as e: # pragma: no cover - logSys.warning("Retrieving own hostnames failed: %s", e) + for fqdn in (False, True): + names.add(DNSUtils.getHostname(fqdn=fqdn)) # cache and return : DNSUtils.CACHE_ipToName.set(key, names) return names