Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
Jeroen Oudshoorn
2023-09-18 08:55:12 +02:00
parent c3c703d02f
commit 2b3f620187
2 changed files with 47 additions and 2 deletions

View File

@ -0,0 +1,47 @@
import logging
import pwnagotchi.ui.components as components
import pwnagotchi.ui.view as view
import pwnagotchi.ui.fonts as fonts
import pwnagotchi.plugins as plugins
import pwnagotchi
import subprocess
class InternetConnectionPlugin(plugins.Plugin):
__author__ = 'adi1708 made by chatGPT'
__version__ = '1.0.0'
__license__ = 'GPL3'
__description__ = 'A plugin that displays the Internet connection status on the pwnagotchi display.'
__name__ = 'InternetConnectionPlugin'
__help__ = """
A plugin that displays the Internet connection status on the pwnagotchi display.
"""
__dependencies__ = {
'pip': ['scapy']
}
__defaults__ = {
'enabled': False,
}
def on_loaded(self):
logging.info("Internet Connection Plugin loaded.")
def on_ui_setup(self, ui):
with ui._lock:
# add a LabeledValue element to the UI with the given label and value
# the position and font can also be specified
ui.add_element('connection_status', components.LabeledValue(color=view.BLACK, label='Internet:', value='',
position=(0, 50), label_font=fonts.Small,
text_font=fonts.Small))
def on_ui_update(self, ui):
with ui._lock:
# 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
ui.set('connection_status', 'Connected')
except subprocess.CalledProcessError:
# if the command failed, it means there is no active Internet connection
ui.set('connection_status', 'Disconnected')

View File

@ -43,7 +43,6 @@ class WpaSec(plugins.Plugin):
except requests.exceptions.RequestException as req_e:
raise req_e
def _download_from_wpasec(self, output, timeout=30):
"""
Downloads the results from wpasec and safes them to output
@ -65,7 +64,6 @@ class WpaSec(plugins.Plugin):
except OSError as os_e:
raise os_e
def on_loaded(self):
"""
Gets called when the plugin gets loaded