Project

General

Profile

Feature #527

Use arp-scan to determine if device is on network or not instead of ping?

Added by ryangrace over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
12/24/2014
Due date:
% Done:

0%

Estimated time:
Resolution:

Description

I have just come over to DomotiGa from an aGocontrol installation (www.agocontrol.com). One of the great modules available in ago was the wifi device detect module which used the utility 'arp-scan' to determine if a device was present on the network or not. The benefit is that my iPhone will not respond to pings while "sleeping" with the screen off, but still shows on the network for arp-scan.

Use case: my phone connects to the wireless network as I approach the house. The phone's presence is used to turn off push notifications I'm interested in only when I'm away from the house. My phone would not respond to pings because it's "sleeping", but would show up in the arp-scan.

Another use: My wife and I both leave the house and our phones are no longer in the arp list. This is used to turn on push notifications to my phone while we're away. When either of us returns the notifications are disabled.

I use events to trigger the notifications. For example, if the front door opens and neither phone is on the network, send a push to my phone.

History

#1 Updated by janno over 4 years ago

Hello, looking at the source code of ago control this should be simple to emulate. You could make a shell script like this:
#!/bin/sh
sudo arp-scan -l | nawk '{print $2}' | grep -c '34:e2:fdabcd:ef'

This script will return 1 if phone with that mac is seen. In domotiga you can make a device of type shell script of which the 1 or 0 will become available in the firstvariable.

Only problem left... arp-scan command only runs with system rights (sudo) and therefore asks for a password. So you have to do something like http://unix.stackexchange.com/questions/18830/how-to-run-a-specific-program-as-root-without-a-password-prompt to overcome this.

#2 Updated by ryangrace over 4 years ago

Thanks, janno. I will give this a try.

I think using cell phone MAC addresses with arp-scan is a "killer" presence detector for home automation. Here are the benefits I see vs. other methods:

  • People tend to carry their phones with them at all times these days, or at least when leaving the house.
  • My wifi network covers a much greater area (the whole house and part of the yard outside) than a bluetooth connection would.
  • Using arp-scan with MAC addresses means we don't have to assign static IP addresses to all the devices we want to track like we do with the Ping plugin.

For these reasons it would be nice to see this functionality become a mainstream DomotiGa plugin instead of having to make it work with a shell script workaround. Though I will certainly go now and try to get the shell script method to work.

Thanks again,

Ryan

#3 Updated by rdnzl over 4 years ago

I will add it to the code, hang on.

#4 Updated by rdnzl over 4 years ago

I have added it to latest beta code, renamed Ping plugin to NetworkDetect plugin.
You can now enable and ping and/or arp-scan, ping will only check devices of type ping (duh), arp-scan will do a network scan (-l) and then check if address (mac or ip) of arp-scan devices is found in it's output, you can even use text as address like oui name (but those can have duplicates)
Also three new Arp-Scan devicetypes are added of which one has Home/Away as status.
Look at the bottom of the 10019to10020.sql file to see what you have to change if you already run beta.

#5 Updated by rdnzl over 4 years ago

  • Status changed from New to Feedback

#6 Updated by ryangrace over 4 years ago

Thanks rdnzl! Will this require enabling root permissions somehow since arp-scan needs root?

I've set up the shell script method but keep getting this in the logs:

2014/12/27 09:54:38 [Shell] Getting value(s) for device 'Ryan cell phone ' with command '/home/ryan/bin/wifidetectryanphone.sh'.
2014/12/27 09:54:38 [Shell] Device with id '64' returned unknown shell error '1'

The script works on the command line and only returns a 1 as a result when my phone is found, otherwise 0. The wiki says any values returned on newlines are interpreted in order as device values, but it looks like the 1 that is returned is causing an error for some reason. Any idea why?

Thanks again,

Ryan

#7 Updated by rdnzl over 4 years ago

Yes you need root access but you can fix this easily by setting the sticky-bit see NetworkDetect wiki page on this wiki..

#8 Updated by ryangrace over 4 years ago

Setting the sticky bit worked like a charm. And the wiki is updated already! Wow. Thanks. I haven't upgraded to the newest beta yet but have been debugging arp-scan reliability on my debian system today and have one more request for the feature. I really hope I'm not pushing my luck too far.

It turns out the results of arp-scan can be unreliable unless the timeout passed is set higher than the default. Many of the wireless devices on my network, including Squeezebox devices, iPhones, iPads, and other tablets, are not showing up in the scan now unless I set the timeout to > 1000ms. Ping tests with my iPhone resulted in me setting the timeout to 5000ms and things are showing up more reliably now. I think "sleeping" devices that are connected to the network need time to wake up and respond.

So would you please either add a field to the ping plugin settings to allow altering the arp-scan timeout or make the timeout passed on the command line with -t ridiculously high (like 5000ms)?

Thanks for your quick response already. I'm impressed coming from other projects recently where it was normal to receive no reply at all to inquiries.

Ryan

#9 Updated by rdnzl over 4 years ago

I noticed that too, sometimes my phone arp response was missing, even if the wif stays on while sleeping.
I added the timeout parameter in latest code and sql upgrade file.

#10 Updated by ryangrace over 4 years ago

I tried to update to minor version 20 this afternoon to try out the new network detect plugin, but found the normal git checkout method outlined in the wiki "Upgrade" section doesn't include this new code. The wiki page about upgrading to the beta branch, which I assume holds the new plugin, mentions it can be tricky getting back to a stable release after upgrading the database to a beta version.

Should I hold tight until the new network detect plugin is merged into stable then upgrade?

Thanks,

Ryan

#11 Updated by rdnzl over 4 years ago

Added to beta and V1.0.020 out later today.

#12 Updated by rdnzl over 4 years ago

  • Status changed from Feedback to Closed

Also available in: Atom PDF