Newer
Older
dhcp2MQTT / docker / dash-listen.py
# sudo apt-get install python-scapy tcpdump tcpreplay wireshark

# Note that wireshark prompts during installation if non-root users
# should be allowed to perform packed capture.

from scapy.all import *
import paho.mqtt.client as mqtt
import os


DASH_INTERFACE=os.environ.get('DASH_INTERFACE')

DASH_MQTT_SERVER = os.environ.get('DASH_MQTT_SERVER')
DASH_MQTT_PORT = os.environ.get('DASH_MQTT_PORT')
DASH_MQTT_TOPIC = os.environ.get('DASH_MQTT_TOPIC')



def arp_display(pkt):
	if (pkt.haslayer(DHCP)):
		print "DHCP from " + pkt[Ether].src
		client.publish(DASH_MQTT_TOPIC + "/mac", str(pkt[Ether]))
	# end if
# end apr_display

client = mqtt.Client()
client.connect(DASH_MQTT_SERVER, DASH_MQTT_PORT, keepalive=60, bind_address="")

try:
	print sniff(prn=arp_display, iface=DASH_INTERFACE, filter="ip", store=0, count=0)
except KeyboardInterrupt:
	if (GLOBAL_DEBUG):
		print("exit")
	# end if
# end try