fallback to localhost if detecting dnsserver fails

This commit is contained in:
Nick Sweeting 2024-10-03 03:53:50 -07:00
parent b36e89d086
commit 490e5ba11d
No known key found for this signature in database
3 changed files with 7 additions and 3 deletions

View file

@ -167,7 +167,11 @@ def get_isp_info(ip=None):
result = subprocess.run(['dig', 'example.com', 'A'], capture_output=True, text=True, check=True).stdout
dns_server = result.split(';; SERVER: ', 1)[-1].split('\n')[0].split('#')[0].strip()
except Exception:
pass
try:
dns_server = Path('/etc/resolv.conf').read_text().split('nameserver ', 1)[-1].split('\n')[0].strip()
except Exception:
dns_server = '127.0.0.1'
print(f'[red]:warning: WARNING: Could not determine DNS server, using {dns_server}[/red]')
# Get DNS resolver's ISP name
# url = f'https://ipapi.co/{dns_server}/json/'