Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions StreamingCommunity/Util/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,19 @@ def format_transfer_speed(self, bytes: float) -> str:
# 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
"""
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:
Expand Down
28 changes: 13 additions & 15 deletions StreamingCommunity/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import argparse
import importlib
import threading, asyncio
from urllib.parse import urlparse
from typing import Callable


Expand Down Expand Up @@ -153,6 +154,7 @@ def initialize():
except:
console.log("[red]Error with loading github.")


def restart_script():
"""Riavvia lo script con gli stessi argomenti della riga di comando."""
print("\nRiavvio dello script...\n")
Expand Down Expand Up @@ -191,6 +193,11 @@ def force_exit():
os._exit(0)


def _extract_hostname(url_string: str) -> str:
"""Safely extracts the hostname from a URL string."""
return urlparse(url_string).hostname


def main(script_id = 0):

color_map = {
Expand All @@ -209,20 +216,11 @@ def main(script_id = 0):
# Create logger
log_not = Logger()
initialize()

# if not internet_manager.check_dns_provider():
# print()
# console.print("[red]❌ ERROR: DNS configuration is required!")
# console.print("[red]The program cannot function correctly without proper DNS settings.")
# console.print("[yellow]Please configure one of these DNS servers:")
# console.print("[blue]• Cloudflare (1.1.1.1) 'https://developers.cloudflare.com/1.1.1.1/setup/windows/'")
# console.print("[blue]• Quad9 (9.9.9.9) 'https://docs.quad9.net/Setup_Guides/Windows/Windows_10/'")
# console.print("\n[yellow]⚠️ The program will not work until you configure your DNS settings.")

# time.sleep(2)
# msg.ask("[yellow]Press Enter to continue ...")

if not internet_manager.check_dns_resolve():

# Get all site hostname
hostname_list = [hostname for site_info in config_manager.configSite.values() if (hostname := _extract_hostname(site_info.get('full_url')))]

if not internet_manager.check_dns_resolve(hostname_list):
print()
console.print("[red]❌ ERROR: DNS configuration is required!")
console.print("[red]The program cannot function correctly without proper DNS settings.")
Expand Down Expand Up @@ -374,4 +372,4 @@ def main(script_id = 0):
# Delete script_id
script_id = TelegramSession.get_session()
if script_id != "unknown":
TelegramSession.deleteScriptId(script_id)
TelegramSession.deleteScriptId(script_id)