Created
September 27, 2015 13:38
-
-
Save werdnum/86c44ea993510b292f3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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