Enhance DNS resolution check to accept a custom list of domains

This commit is contained in:
Alessandro Perazzetta 2025-06-09 00:45:37 +02:00
parent 5a922f84a6
commit 1ab46f2c6d
2 changed files with 8 additions and 5 deletions

View File

@ -320,18 +320,19 @@ class InternManager():
# except Exception:
# return False
def check_dns_resolve(self):
def check_dns_resolve(self, domains_list: list = None):
"""
Check if the system's current DNS server can resolve a domain name.
Works on both Windows and Unix-like systems.
Args:
domains_list (list, optional): List of domains to test. Defaults to common domains.
Returns:
bool: True if the current DNS server can resolve a domain name,
False if can't resolve or in case of errors
bool: True if the current DNS server can resolve a domain name,
False if can't resolve or in case of errors
"""
test_domains = ["github.com", "google.com", "microsoft.com", "amazon.com"]
test_domains = domains_list or ["github.com", "google.com", "microsoft.com", "amazon.com"]
try:
for domain in test_domains:

View File

@ -222,7 +222,9 @@ def main(script_id = 0):
# time.sleep(2)
# msg.ask("[yellow]Press Enter to continue ...")
if not internet_manager.check_dns_resolve():
domains_list = [site_info['full_url'].replace('http://', '').replace('https://', '').strip('/') for site_info in config_manager.configSite.values()]
if not internet_manager.check_dns_resolve(domains_list):
print()
console.print("[red]❌ ERROR: DNS configuration is required!")
console.print("[red]The program cannot function correctly without proper DNS settings.")