mirror of https://github.com/fail2ban/fail2ban
meantime commit: code review, simplification, pythonization, etc. (test cases passed)
parent
a757037671
commit
07c9f38e45
|
@ -375,7 +375,7 @@ class Filter(JailThread):
|
||||||
# @return True if IP address is in ignore list
|
# @return True if IP address is in ignore list
|
||||||
|
|
||||||
def inIgnoreIPList(self, ip, log_ignore=False):
|
def inIgnoreIPList(self, ip, log_ignore=False):
|
||||||
if isinstance(ip, basestring):
|
if not isinstance(ip, IPAddr):
|
||||||
ip = IPAddr(ip)
|
ip = IPAddr(ip)
|
||||||
for net in self.__ignoreIpList:
|
for net in self.__ignoreIpList:
|
||||||
# if it isn't a valid IP address, try DNS resolution
|
# if it isn't a valid IP address, try DNS resolution
|
||||||
|
@ -1037,7 +1037,10 @@ class DNSUtils:
|
||||||
return v
|
return v
|
||||||
# retrieve name
|
# retrieve name
|
||||||
try:
|
try:
|
||||||
v = socket.gethostbyaddr(ip.ntoa())[0]
|
if not isinstance(ip, IPAddr):
|
||||||
|
v = socket.gethostbyaddr(ip)[0]
|
||||||
|
else:
|
||||||
|
v = socket.gethostbyaddr(ip.ntoa())[0]
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
logSys.debug("Unable to find a name for the IP %s: %s", ip, e)
|
logSys.debug("Unable to find a name for the IP %s: %s", ip, e)
|
||||||
v = None
|
v = None
|
||||||
|
|
|
@ -1314,9 +1314,9 @@ class DNSUtilsNetworkTests(unittest.TestCase):
|
||||||
res = DNSUtils.textToIp('www.example.com', 'no')
|
res = DNSUtils.textToIp('www.example.com', 'no')
|
||||||
self.assertEqual(res, [])
|
self.assertEqual(res, [])
|
||||||
res = DNSUtils.textToIp('www.example.com', 'warn')
|
res = DNSUtils.textToIp('www.example.com', 'warn')
|
||||||
self.assertEqual(res, ['93.184.216.34'])
|
self.assertEqual(res, ['93.184.216.34', '2606:2800:220:1:248:1893:25c8:1946'])
|
||||||
res = DNSUtils.textToIp('www.example.com', 'yes')
|
res = DNSUtils.textToIp('www.example.com', 'yes')
|
||||||
self.assertEqual(res, ['93.184.216.34'])
|
self.assertEqual(res, ['93.184.216.34', '2606:2800:220:1:248:1893:25c8:1946'])
|
||||||
|
|
||||||
def testTextToIp(self):
|
def testTextToIp(self):
|
||||||
# Test hostnames
|
# Test hostnames
|
||||||
|
@ -1328,7 +1328,7 @@ class DNSUtilsNetworkTests(unittest.TestCase):
|
||||||
for s in hostnames:
|
for s in hostnames:
|
||||||
res = DNSUtils.textToIp(s, 'yes')
|
res = DNSUtils.textToIp(s, 'yes')
|
||||||
if s == 'www.example.com':
|
if s == 'www.example.com':
|
||||||
self.assertEqual(res, ['93.184.216.34'])
|
self.assertEqual(res, ['93.184.216.34', '2606:2800:220:1:248:1893:25c8:1946'])
|
||||||
else:
|
else:
|
||||||
self.assertEqual(res, [])
|
self.assertEqual(res, [])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue