Skip to content

Instantly share code, notes, and snippets.

@jrheling
Forked from eob/dash-listen-2.py
Last active January 1, 2016 18:33
Show Gist options
  • Save jrheling/6ec8a02332e2315895e7 to your computer and use it in GitHub Desktop.
Save jrheling/6ec8a02332e2315895e7 to your computer and use it in GitHub Desktop.
Simple script to watch for and react to Amazon Dash button pushes.
#!/usr/bin/python
# based on https://medium.com/@edwardbenson/how-i-hacked-amazon-s-5-wifi-button-to-track-baby-data-794214b0bdd8
#
# This is a quick hack. As such, it:
# * lacks exception handling
# * has no pretense of object orientation
# * needs root privs (for network monitoring) but doesn't do anything
# to make that safe (e.g. drop privs, etc.)
# * gets configured manually (see below)
from scapy.all import *
import urllib2, urllib
import time
############################################ start config
ifttt_key = "PUT_YOUR_KEY_HERE"
cloudstitch_username = "YOUR_USERNAME_HERE"
# Maps known MAC addrs of dash buttons to text descriptors
# NB: these descriptors are the logical key used for subsequent config
mac_addrs = {}
mac_addrs['DE:AD:BE:EF:4D:AD'] = "orange" # <<----- put your mac addr[s] here
mac_addrs['DE:AD:BE:EF:4D:AD'] = "white"
# Associates each button with up to one action type.
# Currently supported actions are IFTTT and MagicForm
actions = {}
actions['orange'] = "ifttt"
actions['white'] = "magicform"
# For IFTTT actions, we set which event type is sent
ifttt_actions = {}
ifttt_actions['orange'] = "button_pressed"
# For MagicForm actions, we set which sheet to update on button press
magicform_actions = {}
magicform_actions['white'] = 'magic-form-1'
############################################ end config
def do_print(button):
print "%s button pressed" % button
def call_ifttt(button):
if button in ifttt_actions:
url = "https://maker.ifttt.com/trigger/%s/with/key/%s" % (ifttt_actions[button], ifttt_key)
urllib2.urlopen(url)
#print "sent GET to %s" % url
do_print(button)
def call_magicform(button):
data = urllib.urlencode({'button' : button,
'time' : time.asctime()})
url = "http://api.cloudstitch.com/%s/%s/datasources/sheet" % \
(cloudstitch_username, magicform_actions[button])
req = urllib2.Request(url, data)
urllib2.urlopen(req)
#print "sent POST to %s" % url
do_print(button)
def monitor_whohas(pkt):
if not pkt.haslayer(ARP):
# FIXME how is this getting through the filter passed to scapy?
return
if pkt[ARP].op == 1: #who-has (request)
if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
if pkt[ARP].hwsrc in mac_addrs:
b = mac_addrs[pkt[ARP].hwsrc]
if b in actions:
if actions[b] == "ifttt":
call_ifttt(b)
elif actions[b] == "magicform":
call_magicform(b)
elif actions[b] == "print":
do_print(b)
else:
print "ARP Probe from unknown: " + pkt[ARP].hwsrc
else:
# (for curiosity)
# what do we get other than a who-has from 0.0.0.0?
print "NON WHO-HAS ARP Probe from: " + pkt[ARP].hwsrc
if __name__ == "__main__":
sniff(prn=monitor_whohas, filter="src host 0.0.0.0 and arp", store=0, count=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment