Skip to content

Commit

Permalink
I believe this fixes perfsonar/toolkit#475. Previopusly was only look…
Browse files Browse the repository at this point in the history
…ing in /etc/hosts if name existed. Now combines all sources.
  • Loading branch information
arlake228 committed May 24, 2024
1 parent d1e9fd7 commit e0edc02
Showing 1 changed file with 33 additions and 36 deletions.
69 changes: 33 additions & 36 deletions psconfig/perfsonar-psconfig/psconfig/utilities/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,31 @@ def resolve_address_multi(addresses, timeout=60):
for address in addresses:
#try /etc/hosts first
ip_hosts, host_ips = read_etc_hosts()

if address in host_ips:
results[address] = results.get(address, [])
results[address] += host_ips[address]

else:
#v4 lookup
try:
v4_result = res.resolve(address, 'A')
if v4_result:
results[address] = results.get(address, [])
for result in v4_result:
results[address].append(result.to_text())
except Exception as e:
#can not resolve #####add logging
pass

#v6 lookup
try:
v6_result = res.resolve(address, 'AAAA')
if v6_result:
results[address] = results.get(address, [])
for result in v6_result:
results[address].append(result.to_text())
except Exception as e:
#can not resolve #####add logging
pass

#v4 lookup
try:
v4_result = res.resolve(address, 'A')
if v4_result:
results[address] = results.get(address, [])
for result in v4_result:
results[address].append(result.to_text())
except Exception as e:
#can not resolve #####add logging
pass

#v6 lookup
try:
v6_result = res.resolve(address, 'AAAA')
if v6_result:
results[address] = results.get(address, [])
for result in v6_result:
results[address].append(result.to_text())
except Exception as e:
#can not resolve #####add logging
pass

return results

Expand All @@ -114,18 +112,17 @@ def reverse_dns_multi(addresses, timeout=60):
if address in ip_hosts:
results[address] = results.get(address, [])
results[address] += ip_hosts[address]

else:
#dns reverse lookup
try:
resolver_result = res.query(dns.reversename.from_address(address), 'PTR')
if resolver_result:
results[address] = results.get(address, [])
for result in resolver_result:
results[address].append(str(result).rstrip('.'))
except Exception as e:
#can not resolve #####add logging
pass

#dns reverse lookup
try:
resolver_result = res.query(dns.reversename.from_address(address), 'PTR')
if resolver_result:
results[address] = results.get(address, [])
for result in resolver_result:
results[address].append(str(result).rstrip('.'))
except Exception as e:
#can not resolve #####add logging
pass
return results


Expand Down

0 comments on commit e0edc02

Please sign in to comment.