forked from itsdarklikehell/pwnagotchi-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPDisplay.py
82 lines (73 loc) · 2.69 KB
/
IPDisplay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
############################
# setup is simple
# main.plugins.IPDisplay.skip_devices = [
# 'eth0',
# 'usb0',
# 'bnep0',
# 'wlan0',
# 'ect...'
# ]
# main.plugins.IPDisplay.position = "0, 82"
from pwnagotchi.ui.components import LabeledValue
from pwnagotchi.ui.view import BLACK
import pwnagotchi.ui.fonts as fonts
import pwnagotchi.plugins as plugins
import logging
import time
import subprocess
import ipaddress
class IPDisplay(plugins.Plugin):
__author__ = 'NeonLightning(thank to NurseJackass and jayofelony)'
__version__ = '1.0.0'
__license__ = 'GPL3'
__description__ = 'Display IP addresses on the Pwnagotchi UI'
def __init__(self):
self.options = dict()
self.device_skip_list = ['lo']
self.device_index = 0
self.skip_time = 0
self.ready = False
self.last_update_time = 0
def on_loaded(self):
if 'skip_devices' in self.options:
self.device_skip_list = self.options['skip_devices']
self.options['skip_devices'] = self.device_skip_list
logging.debug("IP Display Plugin loaded.")
def on_ready(self, agent):
self._agent = agent
logging.info("IP Display Plugin ready.")
self.ready = True
def on_ui_setup(self, ui):
pos1 = (0, 82)
if 'position' in self.options:
pos1 = self.options['position']
ui.add_element('ip1', LabeledValue(color=BLACK, label="", value='Initializing...',
position=pos1, label_font=fonts.Small, text_font=fonts.Small))
def get_iface_addrs(self):
command = f"ip -4 -o addr | awk '/inet / {{print $2 \":\" $4}}' | cut -d '/' -f 1"
ifaces = []
for line in subprocess.getoutput(command).split('\n'):
pts = line.strip().split(":")
if pts[0].lower() not in self.device_skip_list:
ifaces.append(line.strip())
return ifaces
def on_ui_update(self, ui):
try:
if time.time() - self.last_update_time < 2:
return
self.last_update_time = time.time()
if self.skip_time + 5 > time.time():
return
self.device_index += 1
self.skip_time = time.time()
ifaces = self.get_iface_addrs()
if self.device_index >= len(ifaces):
self.device_index = 0
current_device = ifaces[self.device_index]
ui.set('ip1', f'{current_device}')
except Exception as e:
logging.exception(repr(e))
def on_unload(self, ui):
self.ready = False
ui.remove_element('ip1')
logging.info("IP Display Plugin unloaded.")