Skip to content

Instantly share code, notes, and snippets.



Last active Mar 21, 2020
What would you like to do?
Monitor Connected Devices to an ASUS Router Using Raspberry Pi
import subprocess
import requests
# MAC address of device running this script
self_mac = "00:11:22:33:44:55"
# MAC address of devices to check
to_monitor = {"66:77:88:99:aa:bb", "cc:dd:ee:ff:00:11"}
# MAC address of device which must be in the LAN for notifications to be sent
i_mac = "22:33:44:55:66:77"
# Path to the status file
record = "/etc/wlan_mon_status"
# Content of the status file
NOTIFIED_FLAG = "notified"
# Read in status file
with open(record) as f:
data =
# Output of ARP table check
out = subprocess.getoutput('ssh admin@ /sbin/arp -n').lower()
if self_mac not in out:
# Error occurred while connecting to router
print("err", out)
if all(i not in out for i in to_monitor):
# All devices to check is disconnected
if NOTIFIED_FLAG not in data:
if i_mac in out:
# only notify if my device is still connected
# Send notification to IFTTT webhook"")
# write flag
with open(record, "w") as f:
# At least one device to check is still connecting
if NOTIFIED_FLAG in data:
# clear flag
with open(record, "w") as f:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment