From 918642568bbd9d3e9322d888e6da84511a7207c3 Mon Sep 17 00:00:00 2001 From: Snuffy2 Date: Mon, 11 Dec 2023 07:38:26 -0500 Subject: [PATCH] Catch errors on IP resolve --- juicepassproxy.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/juicepassproxy.py b/juicepassproxy.py index 492d66a..c971139 100755 --- a/juicepassproxy.py +++ b/juicepassproxy.py @@ -382,7 +382,8 @@ def get_local_ip(): try: s.connect(("10.254.254.254", 1)) local_ip = s.getsockname()[0] - except Exception: + except Exception as e: + logging.warning(f"Unable to get local IP: {e}") local_ip = None s.close() return local_ip @@ -391,8 +392,15 @@ def get_local_ip(): def resolve_ip_external_dns(address, dns="1.1.1.1"): res = resolver.Resolver() res.nameservers = [dns] - - answers = res.resolve(address) + try: + answers = res.resolve(address) + except ( + resolver.LifetimeTimeout, + resolver.NoNameservers, + resolver.NoAnswer, + ) as e: + logging.warning(f"Unable to resolve {address}: {e}") + return None if len(answers) > 0: return answers[0].address