Skip to content

Instantly share code, notes, and snippets.

@yozik04
Created May 9, 2017 08:25
Show Gist options
  • Save yozik04/c367ac0f8647ed2c581eea80c7bcc203 to your computer and use it in GitHub Desktop.
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)
#!/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
@yozik04
Copy link
Author

yozik04 commented May 9, 2017

Logs to syslog of the router:

Went online: 3c:a7:c3:73:67:1d 5c:c7:d3:9a:67:1d
Went offline: 3c:a7:c3:73:67:1d

@gelsas
Copy link

gelsas commented Jan 11, 2018

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