@@ -20,8 +20,7 @@ import winerror
20
20
import winreg
21
21
22
22
import threading
23
- import requests
24
- import urllib3
23
+ import icmplib
25
24
import signal
26
25
import ctypes
27
26
import time
@@ -30,12 +29,12 @@ import re
30
29
31
30
# Define constants
32
31
CHECK_INTERVAL = 2 # Seconds
33
- CONNECT_TEST_URL_AND_RESPONSES = {
34
- "https://www.msftconnecttest.com/connecttest.txt" : "Microsoft Connect Test" , # HTTPS Test #1
35
- "http://www.google.com" : "Google" , # HTTP Test
36
- "https://www.wikipedia.com" : "Wikipedia" , # HTTPS Test #2
37
- "https://www.youtube.com" : "YouTube" , # HTTPS Test #3
38
- }
32
+ CONNECT_TEST_DNS_ADDRESSES = [
33
+ "8.8.8.8" , # Google
34
+ "8.8.4.4" , # Google
35
+ "1.1.1.1" , # Cloudflare
36
+ "1.0.0.1" # Cloudflare
37
+ ]
39
38
SPI_SETDESKWALLPAPER = 20
40
39
SPIF_UPDATEINIFILE = 0x01
41
40
SPIF_SENDWININICHANGE = 0x02
@@ -306,12 +305,12 @@ def extract_title(data):
306
305
return None
307
306
308
307
def check_internet ():
309
- for url , expected_response in CONNECT_TEST_URL_AND_RESPONSES . items () :
308
+ for dns_address in CONNECT_TEST_DNS_ADDRESSES :
310
309
try :
311
310
# Perform internet connectivity tests
312
- response = requests . get ( url , timeout = 5 , verify = False )
313
- if expected_response in ( extract_title ( response . text ) or response . text ) :
314
- print (f"Internet connectivity detected via URL : { url } " )
311
+ dns_host = icmplib . ping ( dns_address , count = 1 , timeout = CHECK_INTERVAL )
312
+ if dns_host . is_alive :
313
+ print (f"Internet connectivity detected via DNS : { dns_address } " )
315
314
return True
316
315
except :
317
316
pass
@@ -468,7 +467,6 @@ def main_loop():
468
467
469
468
if __name__ == "__main__" :
470
469
signal .signal (signal .SIGINT , signal_handler )
471
- urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
472
470
default_transparency = get_transparency_effects ()
473
471
474
472
# Try to load default settings from the registry
0 commit comments