1
- # This tool checks if internet connectivity exists by reaching out to specific websites and checking if they return expected values and
1
+ # This tool checks if internet connectivity exists by pinging some of the well-known public DNS servers
2
2
# display the current state via changes to the background, theme, and icon in the taskbar.
3
3
# * It works even with a tool like FakeNet running (provided it uses the default configuration)
4
4
# If internet is detected, the tool:
@@ -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,19 @@ 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
+
33
+ # - ICMP is a faster and a more-efficient way for checking the connection
34
+ # as it has a minimal fingerprint of 2 packets (echo/reply) per request.
35
+ # - IP addresses are used instead of well-known websites or domains so
36
+ # no DNS resolution is needed.
37
+ # - The used IP addresses are some of the largest public DNS servers to
38
+ # ensure zero or minimal downtime.
39
+ TEST_IPS = [
40
+ "8.8.8.8" , # Google
41
+ "8.8.4.4" , # Google
42
+ "1.1.1.1" , # Cloudflare
43
+ "1.0.0.1" # Cloudflare
44
+ ]
39
45
SPI_SETDESKWALLPAPER = 20
40
46
SPIF_UPDATEINIFILE = 0x01
41
47
SPIF_SENDWININICHANGE = 0x02
@@ -306,12 +312,12 @@ def extract_title(data):
306
312
return None
307
313
308
314
def check_internet ():
309
- for url , expected_response in CONNECT_TEST_URL_AND_RESPONSES . items () :
315
+ for ip_address in TEST_IPS :
310
316
try :
311
317
# 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 } " )
318
+ ip_host = icmplib . ping ( ip_address , 1 )
319
+ if ip_host . is_alive :
320
+ print (f"Internet connectivity detected via IP : { ip_address } " )
315
321
return True
316
322
except :
317
323
pass
@@ -468,7 +474,6 @@ def main_loop():
468
474
469
475
if __name__ == "__main__" :
470
476
signal .signal (signal .SIGINT , signal_handler )
471
- urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
472
477
default_transparency = get_transparency_effects ()
473
478
474
479
# Try to load default settings from the registry
0 commit comments