Skip to content

Instantly share code, notes, and snippets.

@sdsdkkk
Created May 24, 2022 16:02
Show Gist options
  • Save sdsdkkk/c9c2e5c50cfc15c12b377537141b9e65 to your computer and use it in GitHub Desktop.
Save sdsdkkk/c9c2e5c50cfc15c12b377537141b9e65 to your computer and use it in GitHub Desktop.
from tplinkarpmon import TPLinkARPMon
from datetime import datetime
from time import sleep
import sys
tpl = TPLinkARPMon('router-address', 'admin-username', 'admin-password')
DELAY = 60
prev_devices = set()
print('Initialized ARP monitoring util at {}'.format(datetime.now()))
while True:
try:
devices = tpl.connected_devices()
device_macs = []
for d in devices:
device_macs.append(d[0])
curr_devices = set(device_macs)
execution_time = datetime.now()
devices_joining = curr_devices - prev_devices
devices_exiting = prev_devices - curr_devices
prev_devices = curr_devices
if len(devices_joining) > 0:
print('{} - {} device(s) active, {} device(s) joining: {}'.format(execution_time, len(curr_devices), len(devices_joining), devices_joining))
if len(devices_exiting) > 0:
print('{} - {} device(s) active, {} device(s) exiting: {}'.format(execution_time, len(curr_devices), len(devices_exiting), devices_exiting))
sleep(DELAY)
except Exception as e:
print(e)
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment