fix: better dns lookup

pull/106/head
Jeff Culverhouse 4 months ago
parent ef47e7f7b1
commit 172e939ec0

@ -67,7 +67,7 @@ class AmcrestAPI(object):
self.logger.info(f'nslookup {host} got us {host_ip}')
camera = self.get_camera(host_ip)
except Exception as err:
self.logger.error(f'Failed to resolve {host} to ip address: {err}')
self.logger.error(f'Error with {host}: {err}')
device_type = camera.device_type.replace('type=', '').strip()
is_ad110 = device_type == 'AD110'

@ -35,7 +35,10 @@ def is_ipv4(string):
def get_ip_address(string):
if is_ipv4(string):
return string
for i in socket.getaddrinfo(string, 0):
if i[0] is socket.AddressFamily.AF_INET and i[1] is socket.SocketKind.SOCK_RAW:
return i[4][0]
raise Exception(f'failed to find ip address for {string}')
try:
for i in socket.getaddrinfo(string, None):
if i[0] == socket.AddressFamily.AF_INET:
return i[4][0]
except socket.gaierror as e:
raise Exception(f"Failed to resolve {string}: {e}")
raise Exception(f"Failed to find IP address for {string}")
Loading…
Cancel
Save