Writing, publishing, geekdom, and errata.

Determining Who Is Home Based on DD-WRT Connections

No comments
One of the more ambitious things you can do with your phone is to have your home systems start doing things both when you leave and when you get close to home again. The most obvious ones are things like start automatic backups, change audio outputs from local speakers to streaming, and the like. I've also seen where people have mentioned being able to use their home routers to see when others are home as well.

You can use tools like Tasker (for Android) to do this, but there's a whole string of comments about how location awareness can be buggy as hell.... and I'm sure this also leaves iPhone users in the dust.

So here's how you start with this, my droogs.

First, I'm presuming that you're running DD-WRT on your router, or something very similar. I'm also assuming that you've correctly set up passwordless SSH as well. (Guides are here and here; please note that some builds of DD-WRT are flaky when it comes to SSH.)

The fun bit is that all of this happens on a computer you leave at home - whether it's a CHIP, Raspberry Pi, your old machine that runs Kodi for you, or whatever, the magic happens outside the router, and inside the LAN. So make sure that "Allow any IP" is set to off and you've got the "allowed IP" set up properly.

Now, swing over to GitHub and my repository https://github.com/uriel1998/ddwrt-who-is-connected

There's only three scripts in there - and one of them is awfully small.  They should work for both Linux and OSX. 

In short, the scripts have the router run a few simple commands and then parse the output. You'll need to manually change the names of the computers:

from where that dash is over to the / symbol.

The output is both echoed to the terminal at the end and more importantly to a file at $HOME/client_ips.txt (edit line 14 or pass it as the first commandline argument). You can then shift that file out to a webserver or use it to determine if some other action needs to be taken. For example, if my phone's IP is no longer active or reachable, the server knows it's okay to start the online backup, since I am not home and don't need the bandwidth.

There's an example.sh script in there that actually goes through all this, and could just be a drop-in way to do this if you don't mind putting all the variables on the command line.

The great thing about this instead of using location services of any kind is that it's based on a pretty simple and empirical connection. GPS satellites not visible? Who cares? We're simply testing if my phone is connected to the router or not!

You can find the whole shebang over at GitHub:


No comments :