-
-
Save tianweiliu/b51526da804de45fa7dd to your computer and use it in GitHub Desktop.
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 sys | |
from ouimeaux.environment import Environment | |
from scapy.all import * | |
def on_switch(switch): | |
print "WeMo Switch found:", switch.name | |
print "Status:", "off" if switch.get_state() == 0 else "on" | |
def arp_display(pkt): | |
try: | |
if pkt[ARP].op == 1: #who-has (request) | |
if pkt[ARP].psrc == '0.0.0.0': # ARP Probe | |
if pkt[ARP].hwsrc == 'aa:bb:cc:dd:ee:ff': # Dash Button MAC | |
print "Dash Button pressed." | |
list = env.list_switches() | |
if len(list) > 0: | |
switch = env.get_switch(list[0]) | |
print "Toggling", switch.name + " ..." | |
switch.toggle() | |
print "Switch is now", "off." if switch.get_state() == 0 else "on." | |
else: | |
print "No WeMo Switch found." | |
else: | |
print "ARP Probe from unknown device: " + pkt[ARP].hwsrc | |
except: | |
print "Unexpected error:", sys.exc_info()[0] | |
if __name__ == "__main__": | |
print "---------------" | |
print "Dash Switch" | |
print "---------------" | |
env = Environment(on_switch) | |
env.start() | |
print sniff(prn=arp_display, filter="arp", store=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment