List all connected device

Is there a way to get a list of connected device that update every time a new device connect to the LAN, or an old one disconnect? I am trying to create a script that send me notification whenever a new device connect to the router.
The problem is that I am not using the wi-fi on openwrt: the openwrt modem is connecting with an ethernet cable to an Access Point where all wi-fi device connect to.

Just to make sure it's clear... this is probably a bad idea... you will get tons of notifications that you really don't care about. For example, when a battery powered devices are not actively in use, it may power down the radio for a time... sometimes just a few seconds or so even less... then it might reconnect. Or a device goes out of range for just a moment, or a device gets rebooted, etc...

You'll end up with a lot of spam from your script. It won't be pretty or useful.

That said, you can compare the results of arp or ip neigh at some interval to see if anything has changed... or use your DHCP server and trigger your script whenever the DHCP lease table is updated/

I have already tried both arp and ip neigh.
Arp showed lots of device that aren't connected to the network. (40 device when there are only 10)
IP neigh doesn't show reachable device that are connected to the network

There is no simple way. You'll always need to rely on some form of scripting which combines and filters data from multiple sources, such as the ARP table, the neighbor list, the DHCP lease table, the wireless association list, potentially mDNS announcements. As you've noticed, this may report too much hosts (e.g. WAN side neighbors), so you also need to filter, e.g. reverse lookup found neighbors and see if they fall within the LAN subnet IP ranges etc.

1 Like

A less verbose solution could be arpwatch. You get notifications once when a new MAC address is connected to your LAN, or when a known MAC changes IP address. Nothing about disconnections or DHCP address renewal. I find it useful to detect new hosts on my WiFi.

1 Like

Looks like you need to get the events from the AP, not the main router.