If anyone is using an EdgeRouter on EdgeOS, I've put together some scripts which can help determine if someone has arrived or left your network. This doesn't require you to ping devices. Of course there are some concerns around if people disable wireless on their device, but the same concerns work for the ping detection method.
I'd also recommend this be used with a tool for combining multiple presence sensors into a "master" presence to be more accurate:
Another option which is related to ARP but doesn't require the wireless device to be on your network would be to sniff WiFi traffic and look for wireless probes. You need a Linux Device/RPi with a spare wireless adapter that supports monitor mode. The other gotcha here is some mobile devices mask their true MAC address for anonymous probes (they return an Admin OUI). Either way, this would be a router-agnostic way to solve this problem, however it needs someone to change the code (GitHub - bdwilson/wuds: Wireless User Detection System) and add the ability to expire devices that haven't been seen in X amount of time. This has been on my list but I haven't had time.
The generic Linux version -- not specific to any wireless router -- is trivial, as in:
#! /bin/bash
# This script takes a list of [hostname|MAC|IP] and checks whether the specified device[s] are on the LAN.
#
# Will fail miserably with non-CIDR routing, multi-homed hosts, etc.
if [ "X$1" = "X" ] ; then
echo "$0 [hostname|MAC|IP]"
echo ""
echo "Checks whether the specified device[s] are on the LAN."
exit 1
fi
defaultroute=`ip route show|grep default |sed -e "s/default via //" -e "s/\.[0-9][0-9]* .*//" `
subnet=`ip route show |sed -n -e "s,^\(${defaultroute}\.[0-9][0-9]*\)/[0-9].*,\1,p"`
exitval=0
for device in $*
do
# inefficient, but simple
ping -c 2 -W 2 -b $subnet 1> /dev/null 2>&1 # populate the ARP cache
arp -a | grep -qiw $1
if [ $? = 0 ] ; then
echo "Device $1 is present on the LAN ($subnet)"
else
echo "Device $1 is absent from the LAN ($subnet)"
exitval=$((exitval + 1)) # unnecessary
fi
shift
done
exit $exitval
I use arping to do my presence testing. I’m not sure how different it is to the method you use in your script with ping and arp.
I did a bunch of testing with arping and 2 iPhones I have.
The longest an iPhone ever stopped responding to arping was 6s (I logged it for weeks arping every 5s) so I set the timeout for a minute when it left the network. When the phone connects back it picks it up almost instantly.
This was way better than any ping where an iPhone would stop responding for up to 15 minutes once it went to sleep.
I realize this is an old thread but I hope I can ask a few questions.
I have both files on my edgerouter 4, in the correct location, and I have added my pushover user & api keys. I haven't changed anything else and have not created a .arpnotify or .arpignore file yet, meaning no makerAPI connections yet. I just thought the first step would be to get it on there and see if I would start getting pushover notifications.
Questions:
Is there any problem with this initial configuration?
Do I need to restart the router for this script to execute? Or do I need to point to it in some start up file? How does it get initialized?
As long as my devices are using DHCP, this should work even though 90% of my devices are set up with static DHCP reservations?
Thank you for the reply. But you lost me with “cron entries”.
I followed the instructions and have the files on my er4. I manually ran it from the admin login and I received a pushover notification but that is it.
I did reboot the router but the script does not seem to be running.
omg I am NOT a linux guy. I went through the CLI console again and I could not fine the arp_notify directory that I created the last time? I must have been in a temporary sandbox??
this time I used putty and ssh'ed and repeated all the steps. I evidently did not have a crontab previously (I had to do some googling that one) and got it entered. I see that the backup runs daily but the arp_notify runs every 5 mins?? I am still watching my logs.
This just popped up, so I think I got it.
Sep 29 13:05:02 teravani [arp_notify]: No new ARP entries detected.