-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharpalert-service.py
executable file
·34 lines (28 loc) · 1.39 KB
/
arpalert-service.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
#!/usr/bin/env python3
import dbus
import dbus.service
from gi.repository import GObject, GLib
from dbus.mainloop.glib import DBusGMainLoop
# qdbus --system org.arpsentinel /org/arpsentinel sendAlert orig_mac, orig_ip, x, device, alert_type, mac_vendor
class ArpSentinel(dbus.service.Object):
def __init__(self):
self.session_bus = dbus.SystemBus()
name = dbus.service.BusName("org.arpsentinel", bus=self.session_bus)
dbus.service.Object.__init__(self, name, '/org/arpsentinel')
@dbus.service.signal('org.arpsentinel.alerts')
def getAlert(self, orig_mac, orig_ip, x, device, alert_type, mac_vendor=''):
print("%s,%s,%s,%s,%s,%s" % (orig_mac, orig_ip, x, device, alert_type, mac_vendor))
return orig_mac
@dbus.service.method("org.arpsentinel.alerts", in_signature='ssssss', out_signature='as')
def sendAlert(self, orig_mac, orig_ip, x, device, alert_type, mac_vendor=''):
self.getAlert(orig_mac, orig_ip, x, device, alert_type, mac_vendor)
return ["Hello", "from arpsentinel-service.py", "with unique name", self.session_bus.get_unique_name()]
@dbus.service.method("org.arpsentinel.alerts", in_signature='', out_signature='')
def Exit(self):
loop.quit()
if __name__ == '__main__':
# using glib
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
object = ArpSentinel()
loop = GLib.MainLoop()
loop.run()