-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlistener.py
39 lines (34 loc) · 1.35 KB
/
listener.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
#!/usr/bin/python
# coding=utf-8
import logging
import math
import sys
import os
from scapy.all import *
import mapper
import event
import sendData
logger = logging.getLogger('Listener')
logger.debug('Logger for Listener was initialised')
def udp_filter(pkt):
if pkt.haslayer(DHCP):
options = pkt[DHCP].options
for option in options:
if isinstance(option, tuple):
if 'requested_addr' in option:
CurrentEvent = event.Event(pkt.src)
if CurrentEvent.valid is not False:
logger.debug('Creating connector to C8Y´s MQTT')
C8YConnector = sendData.MQTTc8yConnector(ID = pkt.src)
logger.debug('Connector to C8Y´s MQTT created, Creating SendMQTT to C8Y object and inserting event')
C8YSendMQTTData = sendData.SendDataViaMQTT(C8YConnector,CurrentEvent)
logger.debug('Connector to C8Y´s MQTT created, Creating SendMQTT to C8Y object and inserting event')
else:
logger.debug('No DHCP Layer')
sniff(prn=udp_filter, store=0, filter="udp")
if __name__ == "__main__":
try:
logger.info('Starting listener')
except KeyboardInterrupt:
logger.warning('KeyboardInterrupt was called, stopping listener and raising SystemExit')
raise SystemExit