-
-
Save 128keaton/f2e2b116d20b1603a8e3d8b057d03481 to your computer and use it in GitHub Desktop.
Amazon Dash Button ARP listener script (not written by me)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
else: | |
print "Other: " + source_mac + " IP = " + dest_ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment