Last active
May 25, 2017 06:59
-
-
Save gnilchee/33f64eabb1c7c8bc0a5a402aa8361961 to your computer and use it in GitHub Desktop.
Fun script to print to console when device with matching mac address makes a DHCP request
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
#!/usr/bin/env python3 | |
import logging | |
logging.getLogger("scapy.runtime").setLevel(logging.ERROR) | |
from scapy.all import * | |
from datetime import datetime, timedelta | |
from twilio.rest import Client | |
account_sid = "<twilio account sid>" | |
auth_token = "<twilio auth token>" | |
client = Client(account_sid, auth_token) | |
# Set last_seen way far back | |
last_seen = datetime.fromtimestamp(0) | |
alert_delay = timedelta(hours=2) | |
## Setup sniff, filtering for DHCP requests | |
try: | |
while True: | |
mac_address = sniff(iface="eth0", filter="port 67 or port 68", count=1)[Ether][0].src | |
current_time = datetime.now() | |
if mac_address == 'aa:bb:cc:dd:ee:ff': | |
if current_time > last_seen + alert_delay: | |
alert_text="Wife came online at {}".format(current_time.strftime("%c")) | |
client.messages.create( | |
to="+11234567890", | |
from_="+12223334444", | |
body=alert_text | |
) | |
last_seen = current_time | |
except: | |
raise SystemExit("Script was exited.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment