Poor Man's Location-based services with arp-scan and cron
January 24, 2013
Have you ever wanted to have your computer do something when you came home, or when you left? Here's a cheap and easy way to do it.
The arp-scan utility (available in most decent package managers) can scan your local network for active network clients. Just use the --localnet option. If get a response from your mobile phone (identified by mac address) on your local network, then you're (probably) home! Here's an example:
#!/bin/bash
if arp-scan --retry=3 --localnet | grep 'a4:a4:a6:a7:aa:ad'; then
echo "Daddy's home!"
else
echo "Daddy's gone."
fi
Something like this could be easily run from cron (as root). A more sophisticated version would probably need to track the current state, possibly by touching and deleting a file, as to only act when it changes.
Something else to note: My phone, it seems to ignore too many arp requests in a row. Of course YMMV. Once a minute seems to work though. So the --retry option is in there just in case one of the arp packets gets lost.
Comments
You can follow this conversation by subscribing to the comment feed for this post.