From 1519ea6b42d0c9b416d378102c00a98b07f9b956 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Mon, 18 Sep 2023 11:17:55 +0200 Subject: [PATCH] v2.4.2 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/internet-connection.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pwnagotchi/plugins/default/internet-connection.py b/pwnagotchi/plugins/default/internet-connection.py index 25adc78a..f3825875 100644 --- a/pwnagotchi/plugins/default/internet-connection.py +++ b/pwnagotchi/plugins/default/internet-connection.py @@ -5,6 +5,7 @@ import pwnagotchi.ui.fonts as fonts import pwnagotchi.plugins as plugins import pwnagotchi import subprocess +import socket class InternetConnectionPlugin(plugins.Plugin): @@ -37,11 +38,14 @@ class InternetConnectionPlugin(plugins.Plugin): def on_ui_update(self, ui): # check if there is an active Internet connection try: - # use the 'ping' command to check if we can reach a well-known website - output = subprocess.check_output(['ping', '-c', '1', 'google.com']) - # if the command was successful, it means there is an active Internet connection + # See if we can resolve the host name - tells us if there is + # A DNS listening + host = socket.gethostbyname("1.1.1.1") + # Connect to the host - tells us if the host is actually reachable + s = socket.create_connection((host, 80), 2) + s.close() ui.set('connection_status', 'connected') - except subprocess.CalledProcessError: + except: # if the command failed, it means there is no active Internet connection ui.set('connection_status', 'disconnected')