mirror of https://github.com/fail2ban/fail2ban
closes part of gh-1865: fixed "Retrieving own IPs of localhost failed: inet_pton() argument 2 must be string, not int"
some python-versions resp. host configurations causes returning of integer (instead of ip-string)pull/1867/head
parent
d1de20dd41
commit
7867228146
|
@ -69,10 +69,14 @@ class DNSUtils:
|
|||
for fam, ipfam in ((socket.AF_INET, IPAddr.FAM_IPv4), (socket.AF_INET6, IPAddr.FAM_IPv6)):
|
||||
try:
|
||||
for result in socket.getaddrinfo(dns, None, fam, 0, socket.IPPROTO_TCP):
|
||||
ip = IPAddr(result[4][0], ipfam)
|
||||
# if getaddrinfo returns something unexpected:
|
||||
if len(result) < 4 or not len(result[4]): continue
|
||||
# get ip from `(2, 1, 6, '', ('127.0.0.1', 0))`,be sure we've an ip-string
|
||||
# (some python-versions resp. host configurations causes returning of integer there):
|
||||
ip = IPAddr(str(result[4][0]), ipfam)
|
||||
if ip.isValid:
|
||||
ips.append(ip)
|
||||
except socket.error as e:
|
||||
except Exception as e:
|
||||
saveerr = e
|
||||
if not ips and saveerr:
|
||||
logSys.warning("Unable to find a corresponding IP address for %s: %s", dns, saveerr)
|
||||
|
|
|
@ -1852,6 +1852,10 @@ class DNSUtilsNetworkTests(unittest.TestCase):
|
|||
self.assertTrue(IPAddr("93.184.216.34").isInNet(ips))
|
||||
self.assertTrue(IPAddr("2606:2800:220:1:248:1893:25c8:1946").isInNet(ips))
|
||||
|
||||
def testIPAddr_wrongDNS_IP(self):
|
||||
DNSUtils.dnsToIp('`this`.dns-is-wrong.`wrong-nic`-dummy')
|
||||
DNSUtils.ipToName('*')
|
||||
|
||||
def testIPAddr_Cached(self):
|
||||
ips = [DNSUtils.dnsToIp('example.com'), DNSUtils.dnsToIp('example.com')]
|
||||
for ip1, ip2 in zip(ips, ips):
|
||||
|
|
Loading…
Reference in New Issue