From 5df6796e6943807e17b0e5ea962613af8f7b189f Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 2 Jul 2013 23:51:06 -0400 Subject: [PATCH] ENH: DNS resolution -- catch parent exception IMHO there is no good reason to capture only gaierror. on my network it was consistent to error out with ====================================================================== ERROR: testIgnoreIPNOK (testcases.filtertestcase.IgnoreIP) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/yoh/deb/gits/fail2ban/testcases/filtertestcase.py", line 166, in testIgnoreIPNOK self.assertFalse(self.filter.inIgnoreIPList(ip)) File "/home/yoh/deb/gits/fail2ban/server/filter.py", line 277, in inIgnoreIPList ips = DNSUtils.dnsToIp(i) File "/home/yoh/deb/gits/fail2ban/server/filter.py", line 625, in dnsToIp return socket.gethostbyname_ex(dns)[2] error: [Errno 11] Resource temporarily unavailable with this commit tests would pass normally as they should --- server/filter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/filter.py b/server/filter.py index b7c2d091..6cd37ca1 100644 --- a/server/filter.py +++ b/server/filter.py @@ -623,9 +623,9 @@ class DNSUtils: """ try: return socket.gethostbyname_ex(dns)[2] - except socket.gaierror: - logSys.warn("Unable to find a corresponding IP address for %s" - % dns) + except socket.error, e: + logSys.warn("Unable to find a corresponding IP address for %s: %s" + % (dns, e)) return list() dnsToIp = staticmethod(dnsToIp)