Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch errors on IP resolve #45

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions juicepassproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down