import socket | |
import struct | |
import binascii | |
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) | |
source_mac = binascii.hexlify(arp_detailed[5]) | |
source_ip = socket.inet_ntoa(arp_detailed[6]) | |
dest_ip = socket.inet_ntoa(arp_detailed[8]) | |
if source_mac == '74c2467197c': # Put the MAC address of your Amazon Dash Button here | |
print "Button pressed! MAC = " + source_mac | |
else: | |
print "Unknown device. MAC = " + source_mac + ", Source IP = " + source_ip + ", Dest IP = " + dest_ip |
import socket | |
import struct | |
import binascii | |
import time | |
import os | |
rawSocket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003)) | |
lasttime = {} | |
min_interval = 15 # seconds | |
buttons = { 'glad': '74c2467197c', | |
'tide': '74c2467197c' } | |
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) | |
source_mac = binascii.hexlify(arp_detailed[5]) | |
if not (source_mac in lasttime): | |
interval = min_interval # haven't seen this MAC address before | |
else: | |
interval = time.time() - lasttime[source_mac] | |
if interval >= min_interval: | |
lasttime[source_mac] = time.time(); | |
if source_mac == buttons['glad']: | |
print "GLAD button pressed!" | |
os.system('./callsp.sh') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment