Skip to content

Instantly share code, notes, and snippets.

@schwark
Forked from ibrahima/dash-listen-3.py
Last active January 27, 2017 05:33
Show Gist options
  • Save schwark/bc8b467ce6320e52a2f1 to your computer and use it in GitHub Desktop.
Save schwark/bc8b467ce6320e52a2f1 to your computer and use it in GitHub Desktop.
Amazon Dash Button ARP listener script (not written by me)
#!/usr/bin/python
# Adapted from original written by Bob Steinbeiser (https://medium.com/@xtalker)
import socket
import struct
import binascii
def tide_button(arp_detailed):
dest_ip = socket.inet_ntoa(arp_detailed[8])
print 'Tide button pressed, IP = ' + dest_ip
def bounty_button(arp_detailed):
dest_ip = socket.inet_ntoa(arp_detailed[8])
print 'Bounty button pressed, IP = ' + dest_ip
def cottonelle_button(arp_detailed):
dest_ip = socket.inet_ntoa(arp_detailed[8])
print 'Cottonelle button pressed, IP = ' + dest_ip
def unknown_button(arp_detailed):
dest_ip = socket.inet_ntoa(arp_detailed[8])
source_mac = binascii.hexlify(arp_detailed[5])
print 'Unknown button pressed, IP = ' + dest_ip + ' and MAC = ' + source_mac
MAC_MAP = {
'asdfasdfasdf': tide_button,
'werwerererer': bounty_button,
'hjkhjkhjkhjk': cottonelle_button,
}
rawSocket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003))
while True:
packet = rawSocket.recvfrom(2048)
ethernet_header = packet[0][0:14]
ethernet_detailed = struct.unpack("!6s6s2s", ethernet_header)
# skip non-ARP packets
ethertype = ethernet_detailed[2]
if ethertype != '\x08\x06':
continue
arp_header = packet[0][14:42]
arp_detailed = struct.unpack("2s2s1s1s2s6s4s6s4s", arp_header)
src_ip = socket.inet_ntoa(arp_detailed[6])
if src_ip != '0.0.0.0': # ARP Probe
continue
source_mac = binascii.hexlify(arp_detailed[5])
if source_mac in MAC_MAP:
MAC_MAP[source_mac](arp_detailed)
else:
unknown_button(arp_detailed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment