Skip to content

Instantly share code, notes, and snippets.

@kabadisha
Last active December 29, 2020 11:09
Show Gist options
  • Save kabadisha/a87e50311d3ed4589f17a6e37c574a44 to your computer and use it in GitHub Desktop.
Save kabadisha/a87e50311d3ed4589f17a6e37c574a44 to your computer and use it in GitHub Desktop.
Runs on your router to check if devices are connected via wifi. Disables any motioneye network cameras if they are.
#!/bin/sh
# Runs on your router to check if devices are connected via wifi.
# Disables motioneyeos network camera if they are.
# Make sure local dns lookups are enabled on your router.
# On Asus Merlin routers this can be found under Tools > Other Settings >
# 'Wan: Use local caching DNS server as system resolver'
# Requires enabling motioneyeos web control port:
# On the motioneyeos device set webcontrol_localhost to off in /data/etc/motion.conf then reboot the camera.
# You should now be able to access web controll via port 7999. Test with a browser.
# MAC addresses of devices to detect
CHARLIE_PHONE="00:00:00:00:00:00"
ABI_PHONE="00:00:00:00:00:00"
# Create a new file with all of the currently connected devices
echo 'Local results:' > /tmp/wifi-devices.txt
ip neighbour >> /tmp/wifi-devices.txt
# Could also try 'arp -a' command if 'ip neigh' doesnt work.
arp -a >> /tmp/wifi-devices.txt
# Old way (only works on broadcom wifi devices like RT-N66U)
#wl -i eth1 assoclist > /tmp/wifi-devices.txt
#wl -i eth2 assoclist >> /tmp/wifi-devices.txt
echo 'Results from repeater:' >> /tmp/wifi-devices.txt
# Get results from another AP in case devices have roamed there:
ssh -i id_rsa -t [email protected] "ip neighbour; arp -a" | tee -a /tmp/wifi-devices.txt
# Check if either of the devices to detect are connected.
if $(grep -q -i "$CHARLIE_PHONE" /tmp/wifi-devices.txt) \
|| $(grep -q -i "$ABI_PHONE" /tmp/wifi-devices.txt); then
echo "Either or both of the devices detected. Disabling camera..."
wget -O- "http://camera.lan:7999/1/detection/pause" >/dev/null
wget -O- "http://cameratwo.lan:7999/1/detection/pause" >/dev/null
else
echo "Neither device detected. Enabling camera..."
wget -O- "http://camera.lan:7999/1/detection/start" >/dev/null
wget -O- "http://cameratwo.lan:7999/1/detection/start" >/dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment