forked from raspberrycoulis/dashdoorbell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashdoorbell.py
executable file
·51 lines (43 loc) · 1.94 KB
/
dashdoorbell.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
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
# This was based on http://bit.ly/keschy-dash by Keschy but updated for #
# indentation formatting and to remove unnecessary console outputs for running headless. #
# I have also added additional API parameters, such as URL, HTML and sound. #
import datetime
import logging
import urllib
import httplib
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
# Set your Dash Button's MAC address below
DASH_BUTTON_MAC = 'xx:xx:xx:xx:xx:xx'
# Add your Pushover tokens below
APP_TOKEN = 'ADD_YOURS_HERE' # The app token - required for Pushover
USER_TOKEN = 'ADD_YOURS_HERE' # Ths user token - required for Pushover
# Function to trigger the Pushover notification
def pushover():
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": APP_TOKEN, # Get this from your Pushover app
"user": USER_TOKEN, # Get this from your Pushover account
"html":"0", # 1 to enable
"title":"Doorbell!",
"message":"There's somebody at the door!",
"url":"https://ADDYOUROWN.URL",
"url_title":"View Link",
"sound":"pushover",
}), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()
# Function to sniff and capture the Dash button's request online
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:
mac_to_action[pkt.src]()
break
# Below is required to ensure the Dash Button is detected when pushed.
mac_to_action = {DASH_BUTTON_MAC : pushover}
mac_id_list = list(mac_to_action.keys())
sniff(prn=udp_filter, store=0, filter="udp", lfilter=lambda d: d.src in mac_id_list)