-
-
Save mavenius/4b0177cb2d34b464198afd48d1a20224 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
#!/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 | |
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: | |
print "Unknown MAC: [" + source_mac + "] IP = [" + dest_ip + "]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment