Created
July 10, 2019 09:40
-
-
Save karlbeecken/f7c474fffefb43ecbfb733a5910cb006 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 datetime | |
import logging | |
import urllib2 | |
# Constants | |
timespan_threshhold = 3 | |
# Globals | |
lastpress = datetime.datetime(1970,1,1) | |
logging.getLogger("scapy.runtime").setLevel(logging.ERROR) | |
from scapy.all import * | |
def button_pressed_dash1(): | |
global lastpress | |
thistime = datetime.now() | |
timespan = thistime - lastpress | |
if timespan.total_seconds() > timespan_threshhold: | |
current_time = datetime.strftime(thistime, '%Y-%m-%d %H:%M:%S') | |
print 'Dash button pressed at ' + current_time | |
urllib2.urlopen('https://maker.ifttt.com/trigger/dash01/with/key/XsF7Vmz1MJIMg7JWupJ3b') | |
lastpress = thistime | |
def udp_filter(pkt): | |
options = pkt[DHCP].options | |
for option in options: | |
if isinstance(option, tuple): | |
if 'requested_addr' in option: | |
# we've found the IP address, which means its the second and final UDP request, so we can trigger our action | |
mac_to_action[pkt.src]() | |
break | |
mac_to_action = {'ac:63:be:f0:39:42' : button_pressed_dash1} | |
mac_id_list = list(mac_to_action.keys()) | |
print "Waiting for a button press..." | |
sniff(prn=udp_filter, store=0, filter="udp", lfilter=lambda d: d.src in mac_id_list) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment