Created
May 9, 2017 08:25
-
-
Save yozik04/c367ac0f8647ed2c581eea80c7bcc203 to your computer and use it in GitHub Desktop.
Presence detection service on Asus Merlin (should work on DD-WRT as well)
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 | |
### CONFIG | |
INTERFACES="eth1 eth2" | |
### DO NOT EDIT BELOW | |
LAST_MACS="" | |
assoclist() | |
{ | |
{ for i in $INTERFACES; do wl -i $i assoclist; done; } | awk '{print tolower($2)}' | sort -u | |
} | |
list_diff() | |
{ | |
list_1=$1 | |
list_2=$2 | |
for i in $list_1; do | |
found= | |
for j in $list_2; do | |
[[ $i == $j ]] && { found=1; break; } | |
done | |
[[ -z $found ]] && echo $i | |
done | |
} | |
run() | |
{ | |
CURRENT_MACS=$( assoclist ) | |
WENT_ONLINE_MACS=$( list_diff "$CURRENT_MACS" "$LAST_MACS" ) | |
WENT_OFFLINE_MACS=$( list_diff "$LAST_MACS" "$CURRENT_MACS" ) | |
[[ -n "$WENT_ONLINE_MACS" ]] && echo "Went online:" $WENT_ONLINE_MACS | |
[[ -n "$WENT_OFFLINE_MACS" ]] && echo "Went offline:" $WENT_OFFLINE_MACS | |
LAST_MACS="$CURRENT_MACS" | |
} | |
loop() | |
{ | |
while [ 1 ]; do | |
run | |
sleep 5 | |
done | |
} | |
loop | logger |
can i use this script on an fritzbox aswell?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Logs to syslog of the router: