iPhone Presence Detection with hping3 and ARP

Download for your platform here.
(I download on my Win & copied it to openHAB2-userdata samba share)
Example for my Ubuntu server 16.04 LTS:

omr@shs2:~$ sudo dpkg -i /var/lib/openhab2/arping_2.19-1_amd64.deb
[sudo] password for omr:
(Reading database ... 68239 files and directories currently installed.)
Preparing to unpack .../arping_2.19-1_amd64.deb ...
Unpacking arping (2.19-1) over (2.14-1) ...
Setting up arping (2.19-1) ...
Removing obsolete conffile /etc/default/arping ...
Removing obsolete conffile /etc/network/if-up.d/arping ...
Processing triggers for man-db (2.7.5-1) ...

omr@shs2:~$ sudo arping -v
ARPing 2.19, by Thomas Habets <thomas@habets.se>
usage: arping [ -0aAbdDeFpPqrRuUv ] [ -w <sec> ] [ -W <sec> ] [ -S <host/ip> ]
              [ -T <host/ip ] [ -s <MAC> ] [ -t <MAC> ] [ -c <count> ]
              [ -C <count> ] [ -i <interface> ] [ -m <type> ] [ -g <group> ]
              [ -V <vlan> ] [ -Q <priority> ] <host/ip/MAC | -B>
For complete usage info, use --help or check the manpage.
1 Like

Took the arping 2.19 (by Thomas Habets) for a spin pinging a sleeping iPhone 6S.

omr@shs2:/var/lib/openhab2/etc$ sudo arping -vv 192.168.1.51
arping: clock_getres() = 0s 1ns
arping: libnet_init(<null>)
arping: Autodetected interface enp3s0
arping: libnet_init(enp3s0)
Timestamp types:
  Name               Description
  host               Host
arping: Successfully chrooted to /var/run/sshd
arping: Successfully dropped uid/gid to 65534/65534.
arping: pcap_get_selectable_fd(): 5
This box:   Interface: enp3s0  IP: 192.168.1.7   MAC address: 78:24:af:04:e6:94
ARPING 192.168.1.51
arping: sending packet at time 1664524.533523928
Timeout
 - removed timeouts -
arping: sending packet at time 1664545.544827499
60 bytes from f4:31:c3:4e:34:bf (192.168.1.51): index=0 time=171.203 msec
arping: sending packet at time 1664546.545722459
Timeout
 - removed timeouts -
Time since last reply 639-545=94s
arping: sending packet at time 1664639.599271890
60 bytes from f4:31:c3:4e:34:bf (192.168.1.51): index=1 time=124.669 msec
arping: sending packet at time 1664640.599523014
Timeout
 - removed timeouts -
time since last reply 710-639=71s
arping: sending packet at time 1664710.637140904
60 bytes from f4:31:c3:4e:34:bf (192.168.1.51): index=2 time=972.041 msec
60 bytes from f4:31:c3:4e:34:bf (192.168.1.51): index=3 time=972.073 msec
arping: sending packet at time 1664711.637252153
Timeout

These are my properties:

  • The uses_ios_wakeup is On

So is the arping reply interval of up to 94s as expected?
I also did the port 67 forwarding described in the binding doc, but uses_dhcp_listen is still a: no

Just updated to new snapshot with @David_Graeff’s fix.

 openhab> bundle:list | grep -i netw
186 â Active   â  80 â 2.2.0.201709102120     â Network Binding

Properties are now:

When I check top (-V) I can see ping being run regularly, but never arping.
My toolpath is set to /usr/sbin/arping and the openhab user given privilege in sudoers:

openhab@shs2:~$ /usr/sbin/arping
ARPing 2.19, by Thomas Habets <thomas@habets.se>
usage: arping [ -0aAbdDeFpPqrRuUv ] [ -w <sec> ] [ -W <sec> ] [ -S <host/ip> ]
              [ -T <host/ip ] [ -s <MAC> ] [ -t <MAC> ] [ -c <count> ]
              [ -C <count> ] [ -i <interface> ] [ -m <type> ] [ -g <group> ]
              [ -V <vlan> ] [ -Q <priority> ] <host/ip/MAC | -B>
For complete usage info, use --help or check the manpage.

image

Why is my arping never called?

Try arping -c 1 -I eth0 192.168.0.105, adapt the IP.

edit: showing now after one additional restart of openhab
however i still have the same problem as @OMR in regards to the DHCP_state. all settings in regards to port forwarding are done as mentioned in the binding doc, but still getting the “No Access …” message.

@David_Graeff

Got it working and it seems to work really reliable for my P10plus.
however i noticed that in the config nothing is showing for the “Presence _detection_type”
is there a reason for that? (runninh lates bundel 2.2.0.201709102120)

There’s another way: grant your java binary full network access. How to do that is described in the Openhab setup documentation.

The port forwarding section of the binding docu need to be reworked. It doesn’t work in all conditions the documented way.

@David_Graeff

Thanks a lot, looks better, lets see how its working now with this settings and the latest snapshot.

image

HI David,

I am using RPI-3B with openhabian-jessie lite version,
I have installed ARPing with 2.19 version,

I have use sudo visudo and add below line,

openhab ALL=NOPASSWD: /usr/sbin/arping

but openhab still don’t have access right,

I set a rule for test purpose, run command as below

var String arping = executeCommandLine("arping -c 1 -I eth0 192.168.xxx.xx", 120*1000)

Result:
17:58:45.908 [INFO ] [clipse.smarthome.model.script.AirCon] - result:arping: libnet_init(LIBNET_LINK, eth0): libnet_open_link(): UID/EUID 0 or capability CAP_NET_RAW required
arping: you may need to run as root

do you know why? and what should I do now?

Perhaps you should use the openhabian user instead?

I’m pretty sure the openhab user is the right user in this case. OH runs as openhab, not openhabian, so openhab is the one that needs the permission to run arping.

1 Like

actually I did both, result is when use sudo, I don’t require password, but arping still require sudo,

I was fooled by this fact:

When testing the arping command from root@shs2:/home/omr# su -l openhab -s /bin/bash running just the /usr/sbin/arping command seems to work, but providing actual parameters it will tell you you need to be root.

After fiddeling with visudo and entries in /etc/sudoers for hours, I ended up running root@shs2:/home/omr# chmod u+s /usr/sbin/arping. Then it worked!

I can even see in top (-V) that arping is called regularly. But, my Android phone is not seen, even though manual arping detects it. I suspect that is because on Ubuntu, my lan port is not named eth0, but enp3s0:

openhab@shs2:~$ /usr/sbin/arping -c 1 -i enp3s0 192.168.1.50
ARPING 192.168.1.50
60 bytes from 60:f1:89:47:b9:b7 (192.168.1.50): index=0 time=190.029 msec

Could this make the arping call from the binding fail do you think @David_Graeff?

Will try out DHCP tip next :slight_smile:

Could you please share how you did this?

I tried chmod u+s /usr/sbin/arping. but result still the same
it’s even getting worse, I got same warning even use sudo,

Hmm, I also, in the heat of the battle, issued a chmod 777 /usr/sbin/arping command. Maybe the combo is golden?

I gave up, I found run script at router response and reliability much better,
I shall monitor closely for 48 hours.

I modify @Seaside script and run it on router, result looks more reliable than I think



#!/bin/bash

 #Enter your ip of the devices here, separator space
DEVICES="192.168.0.1 192.168.0.2"

for i in `echo $DEVICES`; do
    status=`arp -an $i | awk '{print $4}' | grep "..:..:..:..:..:.."`
    statusMessage="OFF"
    #A mac will be 17 characters including the ":"
    if [ ${#status} -eq 17 ]; then
        echo "Phone $i is detected!"
        statusMessage="ON"
    else
        echo "Phone $i is not present"
        statusMessage="OFF"
    fi
    if [ $i == "192.168.0.1" ]; then
        curl --max-time 2 --connect-timeout 2 --header 'Content-Type: text/plain' --request PUT --data '${statusMessage}' http://192.168.0.255:8080/rest/items/iPhoneA_Online/state
		echo "A's iPhone is ${statusMessage}"
    fi
    if [ $i == "192.168.0.2" ]; then
        curl --max-time 2 --connect-timeout 2 --header 'Content-Type: text/plain' --request PUT --data '${statusMessage}' http://192.168.0.255:8080/rest/items/iPhoneB_Online/state
        echo "B's iPhone is ${statusMessage}"
    fi
done


ARP needs special permissions and I can’t change that fact.

Flushing the arp table every time for a phone presence detection is not the solution, especially not if the script needs root to run.

And no we don’t hardcode eth0 into the code but test on every interface instead actually. What does the properties say?

just a clarification needed.

do i suppose to see the below log entry for a device which is actually not even connected to the network (physically not there) ?

Some device on the network is requesting the address. It is only logged if a DHCP packed has been received.