Skip to content

Instantly share code, notes, and snippets.

@ibrahima
Last active July 14, 2017 17:36
Show Gist options
  • Save ibrahima/5e43439eb71066bf891f to your computer and use it in GitHub Desktop.
Save ibrahima/5e43439eb71066bf891f to your computer and use it in GitHub Desktop.
Amazon Dash Button ARP listener script (not written by me)
import socket
import struct
import binascii
# Written by Bob Steinbeiser (https://medium.com/@xtalker)
rawSocket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
socket.htons(0x0003))
MAC = '74c24671971c'
while True:
packet = rawSocket.recvfrom(2048)
ethernet_header = packet[0][0:14]
ethernet_detailed = struct.unpack('!6s6s2s', ethernet_header)
arp_header = packet[0][14:42]
arp_detailed = struct.unpack('2s2s1s1s2s6s4s6s4s', arp_header)
# skip non-ARP packets
ethertype = ethernet_detailed[2]
if ethertype != '\x08\x06':
continue
source_mac = binascii.hexlify(arp_detailed[5])
dest_ip = socket.inet_ntoa(arp_detailed[8])
if source_mac == MAC:
print "Dash button pressed!, IP = " + dest_ip
@jflowers1974
Copy link

Awesome Stuff!

Anyone else seeing two IPs each time that you press your Dash?

Thanks again - everything worked so easy (and thanks for posting here - the indents really can be a pain).

@bhargavrpatel
Copy link

@ibrahima How do I find the mac address using this?

@rdtracy
Copy link

rdtracy commented Jul 14, 2017

I have tried running this code on my RPI 3 but it doesn't detect my dash button presses. I am running wireshark simultaneously, and I do see the ARP packet on it every time I press the dash button. This shows me the 0x0806 ARP type, which allows me to see the (Dash button) sender MAC address: "AmazonTe_..." as well as IP address. So all seems to be working as expected by the dash button, as observed by my Windows 10 PC. It seems that the PI program is not seeing these packets. The RPI does receive some ARP packets on my local network, just not those sent by the Dash button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment