Skip to content

Instantly share code, notes, and snippets.

@werdnum
Created September 27, 2015 13:38
Show Gist options
  • Save werdnum/86c44ea993510b292f3e to your computer and use it in GitHub Desktop.
Save werdnum/86c44ea993510b292f3e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from scapy.all import *
import calendar
import requests
import time
import yaml
last_triggered = {}
with open("buttons.yaml", "r") as stream:
buttons = yaml.load(stream)
print "Ready"
def arp_display(pkt):
if 'ARP' in pkt and pkt[ARP].op == 1: # who-has (request)
if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
mac = pkt[ARP].hwsrc
if mac in buttons:
event = buttons[mac]
ts = calendar.timegm(time.gmtime())
if event in last_triggered:
if ts < (last_triggered[event] + 30):
return
try:
requests.post('http://localhost:8123/api/events/'+event,
headers={
'x-ha-access': '****',
'content-type': 'application/json'
})
last_triggered[event] = ts
except:
print "Error"
else:
print("ARP Probe from unknown device: " + mac)
sniff(prn=arp_display, filter="arp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment