-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlisten.py
27 lines (23 loc) · 1.3 KB
/
listen.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
#!/usr/bin/python2
# -*- coding: utf-8 -*-
from scapy.all import sniff, ARP
from datetime import datetime, timedelta
# import requests # Use requests to trigger the ITTT webhook
from send_mail import send_mail # This function sends mails directly
last_press = datetime.now() - timedelta(seconds=10)
def arp_received(packet):
if packet[ARP].op == 1 and packet[ARP].hwdst == '00:00:00:00:00:00':
if packet[ARP].hwsrc == '50:f5:da:6f:98:6c': # This is the MAC of the first dash button
global last_press
now = datetime.now()
if last_press + timedelta(seconds=5) <= now:
print("Button pressed!")
last_press = now
# requests.get("https://maker.ifttt.com/trigger/dash_button_pressed/with/key/bVTfJ-_fhDejXSGgGnLdfU")
send_mail("[email protected]", subject="Dash button gedrückt",
text="Hallo,\n\nder Dash-Button wurde gerade gedrückt.\n\nViele Grüße,\n dein Raspi")
elif packet[ARP].hwsrc != 'b8:27:eb:17:d5:22': # If it is not the MAC of the Raspi it could be another button
print("Unknown Device connecting: " + packet[ARP].hwsrc)
if __name__ == "__main__":
print("Listening for ARP packets...")
sniff(prn=arp_received, iface="wlan0", filter="arp", store=0, count=0)