From 172e939ec0a76c4b4b64f70a1d6d84d20b20e2fa Mon Sep 17 00:00:00 2001 From: Jeff Culverhouse Date: Thu, 9 Oct 2025 16:30:39 -0400 Subject: [PATCH] fix: better dns lookup --- amcrest_api.py | 2 +- util.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/amcrest_api.py b/amcrest_api.py index b0ad1fa..86e51f6 100644 --- a/amcrest_api.py +++ b/amcrest_api.py @@ -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' diff --git a/util.py b/util.py index 5212308..b61f84b 100644 --- a/util.py +++ b/util.py @@ -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}') \ No newline at end of file + 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}") \ No newline at end of file