Skip to content

Commit eec0d42

Browse files
AlessandroPerazzettagithub-actions[bot]Arrowar
authored
Check dns resolve domains (#338)
* refactor: streamline proxy checking in search function * refactor: update DNS check method, try a real dns resolution instead of checking dns provider * Fix merge conflicts * Automatic domain update [skip ci] * Automatic domain update [skip ci] * Automatic domain update [skip ci] * Enhance DNS resolution check to accept a custom list of domains * Update run.py --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: None <[email protected]>
1 parent 1d38d04 commit eec0d42

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

StreamingCommunity/Util/os.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,19 @@ def format_transfer_speed(self, bytes: float) -> str:
320320
# except Exception:
321321
# return False
322322

323-
def check_dns_resolve(self):
323+
def check_dns_resolve(self, domains_list: list = None):
324324
"""
325325
Check if the system's current DNS server can resolve a domain name.
326326
Works on both Windows and Unix-like systems.
327327
328+
Args:
329+
domains_list (list, optional): List of domains to test. Defaults to common domains.
330+
328331
Returns:
329332
bool: True if the current DNS server can resolve a domain name,
330333
False if can't resolve or in case of errors
331334
"""
332-
test_domains = ["github.com", "google.com", "microsoft.com", "amazon.com"]
335+
test_domains = domains_list or ["github.com", "google.com", "microsoft.com", "amazon.com"]
333336

334337
try:
335338
for domain in test_domains:

StreamingCommunity/run.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import argparse
1010
import importlib
1111
import threading, asyncio
12+
from urllib.parse import urlparse
1213
from typing import Callable
1314

1415

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

157+
156158
def restart_script():
157159
"""Riavvia lo script con gli stessi argomenti della riga di comando."""
158160
print("\nRiavvio dello script...\n")
@@ -191,6 +193,11 @@ def force_exit():
191193
os._exit(0)
192194

193195

196+
def _extract_hostname(url_string: str) -> str:
197+
"""Safely extracts the hostname from a URL string."""
198+
return urlparse(url_string).hostname
199+
200+
194201
def main(script_id = 0):
195202

196203
color_map = {
@@ -209,20 +216,11 @@ def main(script_id = 0):
209216
# Create logger
210217
log_not = Logger()
211218
initialize()
212-
213-
# if not internet_manager.check_dns_provider():
214-
# print()
215-
# console.print("[red]❌ ERROR: DNS configuration is required!")
216-
# console.print("[red]The program cannot function correctly without proper DNS settings.")
217-
# console.print("[yellow]Please configure one of these DNS servers:")
218-
# console.print("[blue]• Cloudflare (1.1.1.1) 'https://developers.cloudflare.com/1.1.1.1/setup/windows/'")
219-
# console.print("[blue]• Quad9 (9.9.9.9) 'https://docs.quad9.net/Setup_Guides/Windows/Windows_10/'")
220-
# console.print("\n[yellow]⚠️ The program will not work until you configure your DNS settings.")
221-
222-
# time.sleep(2)
223-
# msg.ask("[yellow]Press Enter to continue ...")
224-
225-
if not internet_manager.check_dns_resolve():
219+
220+
# Get all site hostname
221+
hostname_list = [hostname for site_info in config_manager.configSite.values() if (hostname := _extract_hostname(site_info.get('full_url')))]
222+
223+
if not internet_manager.check_dns_resolve(hostname_list):
226224
print()
227225
console.print("[red]❌ ERROR: DNS configuration is required!")
228226
console.print("[red]The program cannot function correctly without proper DNS settings.")
@@ -374,4 +372,4 @@ def main(script_id = 0):
374372
# Delete script_id
375373
script_id = TelegramSession.get_session()
376374
if script_id != "unknown":
377-
TelegramSession.deleteScriptId(script_id)
375+
TelegramSession.deleteScriptId(script_id)

0 commit comments

Comments
 (0)