Ping-based device tracker?

Hi,

My LAN devices all have a static IP. I would like to see the known_hosts.yaml file get extended to allow an IP property so that a new ping-based device tracker can be used to get the most accurate results for devices on my lan.

I envision this being more of a service to monitor when my computers are up/down, than when devices connect to/leave a zone.

Currently, I am using both the nmap-based and asuswrt-based device tracking, but both of these, even together, don’t report the actual status of devices on my lan with the accuracy I’d like.

The asuswrt device tracker, while can easily see all devices are actually on my network, doesn’t update a device as being offline fast enough as it is pulling from a combination of dhcp leases as well as ip neigh, and I fear the dhcp.leases file does not update as fast as I’d like when a host goes down.

The nmap-based tracker has been absolutely solid is knowing when a device is up or down quickly, but I’ve experienced tons of issues where this tracker will not see some devices in known_hosts as ever being online (no idea why) and will not pick up any new devices on my network.

I am happy to manually update the known_hosts.yaml file whenever I add a new device to my network (as I have to assign it a static ip). Hopefully with the ping-based tracker, I can instantly see when known devices are online or not.

Last time I checked was the main issue with python ping binding/implementations that they require administrative rights.

Where did you see this?

That’s probably the reason your nmap tracker is missing some devices: without root permissions, nmap is not allowed to make some specific scans, which results for example in my computer being detected on Linux, but not on Windows. I don’t have the source handy, but the options actually used by the nmap tracker are the most efficient possible (as far as I can tell with my limited nmap knowledge) without any root permissions. I tried by hand another option (can’t remember which one exactly), which detected my Windows as up, but needed root.

At least on Linux only root has access to raw sockets. No, applies to Windows a well, acc. to pying.

Thanks all! Ill look into giving nmap root capability so that normal user can get the info i need.

@cmsimike maybe you can try this device tracker I made for asuswrt: Alternate device_tracker component for ASUSWRT
The status gets updated almost instantly. Only problem is that I have no clue if it works on different asus routers or firmware verisions. I only know it works for my RT-AC66U on firmware 9.0.0.4.380_2695.

hey @cmsimike any luck with running nmap as privileged? I’m also having issues with nmap component, it doesn’t detect windows 10 machines. I tried this tutorial but with no luck

I gave nmap admin as well as using nmap in conjunction with the asuswrt functionality. while not great, it does get the job done

I gave nmap capabilities to run as non-root to my user following the link. Then, I modified the nmap tracker, to change the options: options = "-sS --privileged --host-timeout 5s". With this change, it works fine: it detects my Window 10 machine it didn’t detect before.

I’ve had the issue where it seems that nmap would mark devices as not home even if they were online, only to mark them as home in the next update. do you see something similar?

I had originally thought, when i saw your message, that --host-timeout 5s is what i’d need to fix that, but it seems host timeout is already specified.

No, I didn’t notify any weird behavior. Before the change, my Windows machine was detected once when it was booting, then considered away until the end of times (or, more often, a reboot :-p). Now, I didn’t make extensive tests, but it seems to be always detected.

I know this is a few months back, but could you outline how you did this? I’m having the same issue with a Windows 10 machine never showing as up. Running nmap shows it as down, but running sudo nmap shows it as up.

I understand the part about setting the capabilities but I’m unclear on how to set the options in the nmap tracker.

Thanks!

For that, I changed the nmap_tracker’s code in hass source-tree — not that clean. You can see the options passed to nmap here: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/device_tracker/nmap_tracker.py#L96

Thanks so much! I feel kind of dumb for not thinking of looking there.

One last question if you would; I’m not on a dev build nor do I have any HA git pulls, so besides the obvious issue of having to manually change it, will this cause any issues with updates? I’m on a Pi using the AIO installer.

Thanks again for replying as I know this was an old thread.

Well I don’t know exactly how the AIO installer works for the upgrades, it will maybe refuse to upgrade if a file has been changed locally - or overwrite it. You’ll probably have to try :slight_smile:

1 Like

Thanks; I think I’ll ask around a bit before trying this then.