Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Nov 26, 2015

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

This comment has been minimized.

Copy link

commented Mar 20, 2016

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

@rdtracy

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.