Skip to content

Instantly share code, notes, and snippets.

@andrewthetechie
Created October 20, 2018 04:15
Show Gist options
  • Save andrewthetechie/416201c4e315c880870726eda444052d to your computer and use it in GitHub Desktop.
Save andrewthetechie/416201c4e315c880870726eda444052d to your computer and use it in GitHub Desktop.
from pyHS100 import Discover
from scapy.all import *
living_room_lights = []
dining_room_lights = []
kitchen_lights = []
living_room_on = False
dining_room_on = False
kitchen_on = False
def arp_display(pkt):
global living_room_lights
global dining_room_lights
global kitchen_lights
global living_room_on
global dining_room_on
global kitchen_on
if pkt[ARP].op == 1: # who-has (request)
# Gatorade 1 - Living Room Toggle
# Gatorade 2 - Living Room Toggle
if str(pkt[ARP].hwsrc) in ['f0:27:2d:b6:b7:14', '74:75:48:d2:32:17']:
print("Toggling Living Room")
if living_room_on:
for light in living_room_lights:
light.turn_off()
living_room_on = False
else:
for light in living_room_lights:
light.turn_on()
living_room_on = True
# Schwarzkopf 1 - Dining Room Toggle
if str(pkt[ARP].hwsrc) == "44:65:0d:7c:7f:51":
print("Toggling Dining Room")
if dining_room_on:
for light in dining_room_lights:
light.turn_off()
dining_room_on = False
else:
for light in dining_room_lights:
light.turn_on()
dining_room_on = True
else:
print(f"ARP Probe from unknown device: {pkt[ARP].hwsrc}")
if __name__ == "__main__":
print("Discovering Devices")
for dev in Discover.discover().values():
print(dev)
if "kitchen" in dev.alias.lower():
kitchen_lights.append(dev)
if dev.is_on:
kitchen_on = True
if "living" in dev.alias.lower():
living_room_lights.append(dev)
if dev.is_on:
living_room_on = True
if "dining" in dev.alias.lower():
dining_room_lights.append(dev)
if dev.is_on:
dining_room_on = True
print("Devices discoverered, waiting for switch arp")
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