Created
February 13, 2021 18:54
-
-
Save kabadisha/40569682059aa1509964ab3ebd4f779b to your computer and use it in GitHub Desktop.
Script to check if your phone is at home and disable Shinobi cameras. Runs as a cron job on an Asus router
This file contains 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
#!/bin/sh | |
set -e | |
set -u | |
# Runs on your router to check if devices are connected via wifi. | |
# Disables motion detection on Shinobi network cameras 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' | |
# Also requires curl and jq for processing the JSON response to get the auth token for the ZM API. | |
SHINOBI_URI="https://shinobi.url/shinobi" | |
API_KEY="[your api key]" | |
GROUP_KEY="[your group key]" | |
# 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..." | |
curl -s -XGET "$SHINOBI_URI/$API_KEY/monitor/$GROUP_KEY/[MONITOR_ID]/stop" >/dev/null | |
else | |
echo "Neither device detected. Enabling camera..." | |
curl -s -XGET "$SHINOBI_URI/$API_KEY/monitor/$GROUP_KEY/[MONITOR_ID]/start" >/dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment