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}') self.logger.info(f'nslookup {host} got us {host_ip}')
camera = self.get_camera(host_ip) camera = self.get_camera(host_ip)
except Exception as err: 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() device_type = camera.device_type.replace('type=', '').strip()
is_ad110 = device_type == 'AD110' is_ad110 = device_type == 'AD110'

@ -35,7 +35,10 @@ def is_ipv4(string):
def get_ip_address(string): def get_ip_address(string):
if is_ipv4(string): if is_ipv4(string):
return string return string
for i in socket.getaddrinfo(string, 0): try:
if i[0] is socket.AddressFamily.AF_INET and i[1] is socket.SocketKind.SOCK_RAW: for i in socket.getaddrinfo(string, None):
return i[4][0] if i[0] == socket.AddressFamily.AF_INET:
raise Exception(f'failed to find ip address for {string}') 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