home-assistant-arpscan_tracker icon indicating copy to clipboard operation
home-assistant-arpscan_tracker copied to clipboard

How and does it work?

Open geedsen opened this issue 1 year ago • 19 comments
trafficstars

I installed it, added it to the configuration and restarted HA. But where do I see the results of the scan? And in terminal if I type arp-scan I get this:

image

geedsen avatar Oct 03 '24 18:10 geedsen

The instructions do not explain how install arp-scan in the HA container. I gave up.

tomchiverton avatar Nov 02 '24 17:11 tomchiverton

Back in the days the tool was installed in the default ha image. But HA developers removed everything they think didn't belong there. So I added an install command which runs when my integration is started, but it seems it does not work anymore or fails on some install types, or both. I will have a look when I have some spare time.

cyberjunky avatar Nov 02 '24 18:11 cyberjunky

Thanks.

I found the install code in https://github.com/cyberjunky/home-assistant-arpscan_tracker/blob/master/custom_components/arpscan_tracker/device_tracker.py#L60

And can report it fails because the package manager it assumes to be present isn't.

# whoami
root
# apk add arp-scan
-sh: apk: not found
# 

tomchiverton avatar Nov 06 '24 10:11 tomchiverton

Maybe instead of subprocess.getoutput("arp-scan "+options) we could do with pure python https://pypi.org/project/arpwitch/ ?

tomchiverton avatar Nov 06 '24 10:11 tomchiverton

@tomchiverton not sure, scapy and arpwitch need root permissions. What is the OS you run on, does it have another pkg manager installed?

cyberjunky avatar Nov 06 '24 11:11 cyberjunky

It's running under KVM, as per https://www.home-assistant.io/installation/linux

So being root isn't an issue, I think? Output above was directly from 'virtsh console' after entering "root" at the HA login prompt

tomchiverton avatar Nov 06 '24 17:11 tomchiverton

Does apt-get ... command work instead of apk? Or also not available?

cyberjunky avatar Nov 07 '24 12:11 cyberjunky

No, none of these are available in HAOS.

tomchiverton avatar Nov 07 '24 22:11 tomchiverton

haos has "arp" commond, can add-on use this? like "arp |grep eth0".

here is log: :/config# arp |grep ether 192.168.100.185 ether 68:ab:bc:c6:d5:8f C enp5s0 ricecooker.lan ether cc:b5:d1:12:25:61 C enp5s0 curtainlivingroom.lan ether 7c:c2:94:5d:be:34 C enp5s0 curtainbedroom.lan ether 7c:c2:94:5e:2e:44 C enp5s0 xiaoduaudiospeaker.lan ether 88:2d:53:3f:f8:cf C enp5s0 gassensor.lan ether dc:ed:83:20:d8:21 C enp5s0 172.18.0.3 ether 02:42:ac:12:00:03 C br-fe6cca2934a7 xiaomi-humidifier-p3_mi ether 64:9e:31:38:90:06 C enp5s0 172.18.0.2 ether 02:42:ac:12:00:02 C br-fe6cca2934a7 youyanji.lan ether 68:ab:bc:b6:9b:28 C enp5s0 yugang.lan ether 68:ab:bc:b5:f2:d5 C enp5s0 boardlinkremote.lan ether 34:ea:34:c7:3c:28 C enp5s0 172.17.0.2 ether 02:42:ac:11:00:02 C docker0 mideafriger.lan ether 9c:c1:2d:be:dc:86 C enp5s0 172.17.0.3 ether 02:42:ac:11:00:03 C docker0 mijiahub.lan ether 54:ef:44:47:6d:5b C enp5s0 192.168.100.240 ether b8:50:d8:56:91:d5 C enp5s0 mediaclothesdryer.lan ether 10:2c:8d:fc:e6:99 C enp5s0 washer.lan ether 88:f2:bd:7b:38:d2 C enp5s0 dreamcleanbot.lan ether 70:c9:32:08:42:8b C enp5s0 iStoreOS.lan ether 60:be:b4:04:04:ed C enp5s0 192.168.100.77 ether c0:39:37:18:31:e2 C enp5s0 fryer.lan ether 68:ab:bc:93:ac:ef C enp5s0 ax6000.lan ether 3c:cd:57:fa:d6:00 C enp5s0 computerlight.lan ether cc:b5:d1:2e:bf:d6 C enp5s0

Memo654 avatar Nov 18 '24 04:11 Memo654

I can not locate that command here on the latest haos

pi@pi5:~ $ sudo virsh console haos
Connected to domain 'haos'
Escape character is ^] (Ctrl + ])

homeassistant login: root
Welcome to Home Assistant OS.

Use `ha` to access the Home Assistant CLI.
# arp
-sh: arp: not found
# 

tomchiverton avatar Nov 19 '24 17:11 tomchiverton

Well, I just tested the docker version of homeassistant, using the docker exec -it homeassistant /bin/bash command to enter homeassistant. The two may be different.

Memo654 avatar Nov 20 '24 06:11 Memo654

The two are very different. As I understand it, HA under Docker is "HA Core" and doesn't support addons, for instance; https://www.home-assistant.io/installation/#advanced-installation-methods

tomchiverton avatar Nov 20 '24 12:11 tomchiverton

I can confirm it no longer works. Running supervised ...

Paul-Vdp avatar Dec 18 '24 08:12 Paul-Vdp

We are not talking about addons, this is an integration. There already was also an arp integration back then but it is slow, that was the reason I created the arp-scan version. I will have another look into a python only version, but it's not a matter of a search and replace.

cyberjunky avatar Dec 18 '24 10:12 cyberjunky

there is an arping command in homeassistant/home-assistant

c843b3178ffd:/config# arping
BusyBox v1.37.0 (2024-11-19 21:09:16 UTC) multi-call binary.

Usage: arping [-fqbDUA] [-c CNT] [-w TIMEOUT] [-I IFACE] [-s SRC_IP] DST_IP

Send ARP requests/replies

        -f              Quit on first ARP reply
        -q              Quiet
        -b              Keep broadcasting, don't go unicast
        -D              Exit with 1 if DST_IP replies
        -U              Unsolicited ARP mode, update your neighbors
        -A              ARP answer mode, update your neighbors
        -c N            Stop after sending N ARP requests
        -w TIMEOUT      Seconds to wait for ARP reply
        -I IFACE        Interface to use (default eth0)
        -s SRC_IP       Sender IP address
        DST_IP          Target IP address

iwm911 avatar Jan 26 '25 14:01 iwm911

From the "ha" shell, that works too .

IDK if you can do that from an extension like this one.

# docker ps
CONTAINER ID   IMAGE                                                       COMMAND               CREATED        STATUS      PORTS                                                                                                                          NAMES
8131728c77c7   homeassistant/aarch64-addon-mosquitto:6.5.0                 "/init"               5 days ago     Up 5 days   0.0.0.0:1883-1884->1883-1884/tcp, :::1883-1884->1883-1884/tcp, 0.0.0.0:8883-8884->8883-8884/tcp, :::8883-8884->8883-8884/tcp   addon_core_mosquitto
2e646aea3aa4   ghcr.io/home-assistant/aarch64-hassio-multicast:2024.03.0   "/init"               5 days ago     Up 5 days                                                                                                                                  hassio_multicast
941b94b6ae6c   ghcr.io/home-assistant/aarch64-hassio-audio:2023.12.0       "/init"               5 days ago     Up 5 days                                                                                                                                  hassio_audio
3f3f439a0c3c   ghcr.io/home-assistant/aarch64-hassio-dns:2024.12.0         "/init"               5 days ago     Up 5 days                                                                                                                                  hassio_dns
aca7ea82ec0a   ghcr.io/home-assistant/aarch64-hassio-cli:2024.09.0         "/init"               5 days ago     Up 5 days                                                                                                                                  hassio_cli
c628f32d3c8b   ghcr.io/home-assistant/aarch64-hassio-supervisor:latest     "/init"               5 days ago     Up 5 days                                                                                                                                  hassio_supervisor
88090882d878   ghcr.io/home-assistant/qemuarm-64-homeassistant:2025.1.4    "/init"               8 days ago     Up 5 days                                                                                                                                  homeassistant
673715bf5095   ghcr.io/home-assistant/aarch64-hassio-observer:2023.06.0    "/usr/bin/observer"   3 months ago   Up 5 days   0.0.0.0:4357->80/tcp, [::]:4357->80/tcp                                                                                        hassio_observer
# docker exec -it 88090882d878 /bin/bash
homeassistant:/config# arping
BusyBox v1.37.0 (2024-11-19 21:09:16 UTC) multi-call binary.

Usage: arping [-fqbDUA] [-c CNT] [-w TIMEOUT] [-I IFACE] [-s SRC_IP] DST_IP

Send ARP requests/replies

        -f              Quit on first ARP reply
        -q              Quiet
        -b              Keep broadcasting, don't go unicast
        -D              Exit with 1 if DST_IP replies
        -U              Unsolicited ARP mode, update your neighbors
        -A              ARP answer mode, update your neighbors
        -c N            Stop after sending N ARP requests
        -w TIMEOUT      Seconds to wait for ARP reply
        -I IFACE        Interface to use (default eth0)
        -s SRC_IP       Sender IP address
        DST_IP          Target IP address

tomchiverton avatar Feb 02 '25 13:02 tomchiverton

Why do you say it does not work? I just found this integration today because I want to track devices using ARP scan, just installed it, followed the instructions and I can see in "Developer Tools" > "States all the network devices as device_trackers. Isn't this not working for you? or are you expecting or want to do something different?

Deividdfg avatar Mar 24 '25 21:03 Deividdfg

Why do you say it does not work? I just found this integration today because I want to track devices using ARP scan, just installed it, followed the instructions and I can see in "Developer Tools" > "States all the network devices as device_trackers. Isn't this not working for you? or are you expecting or want to do something different?

https://github.com/cyberjunky/home-assistant-arpscan_tracker/issues/18#issuecomment-2459410442

tomchiverton avatar Mar 26 '25 19:03 tomchiverton

Just installed this integration. After about an hour sniffing around and reading all sorts of manuals, I finally got it working.

@cyberjunky I strongly recommend updating the Readme.md with usage manual. Something like this:

  1. install HACS
  2. install this custom integration
  3. configure
  4. check config and restart (all good up to this point)
  5. login to your network router and set static IP in DHCP settings for the device you wish to track (phone for example) - not required, but recommended
  6. after restart go to the root folder of the HA config
  7. search for the file known_devices.yaml, it will contain found devices on the network
  8. update the records as needed (see: https://www.home-assistant.io/integrations/device_tracker/); mainly set name: <friendly name that will appear in HA> and track: true
  9. restart HA
  10. go to Developer tools -> States; in the filter type device_tracker; check if devices respond as required (toggle phone's wifi on and off, if tracking the phone, wait for at least the preset time in the config file)
  11. to set up automations, do not use Zone feature (looks okay, but does not work)
  12. set up automations using State feature:
triggers:
  - trigger: state
    entity_id:
      - device_tracker.<mac address of the tracked device>
    from: home
    to: not_home
    for:
      hours: 1
      minutes: 0
      seconds: 0
conditions: []
actions:
  - action: notify.telegram_myphone
    metadata: {}
    data:
      message: Leaving! Bye :)
mode: single

My setup: Synology NAS -> Docker -> HA in the docker -> ARP works fine

aly-fly avatar Oct 18 '25 20:10 aly-fly