Get All Clients API Help

Hey all!.

I'm looking to at creating an API Endpoint for one of my routers. I'm trying to get a list of all connected clients including their IP/Mac/Online-Offline/Hostname/Vendor.

Now I've seen a lot of people recommend using the likes of:

ubus call hostapd.wlan0 get_clients


cat /tmp/dhcp.leases

and a few others, but nothing that I found that could reliably output most, if not half, of the stuff I wanted.

My question is, is there another command I can use that could get me closer? Or is this something I should do programmatically using C or Lua & if so, any advice?


There is;


I don't think that's quite what i'm after

There is no such API call available. You'll need to develop custom code merging the information from ip -4 neigh, ip -6 neigh, /tmp/dhcp.leases, /tmp/hosts/odhcpd, iwinfo wlanX assoclist.

Determining the vendor requires shipping a copy of an OUI lookup database which is relatively large (1.5MB uncompressed). But even with that in place, you'll only be able to determine the vendor of direct link local peers (there will be no MAC address information available for clients multiple hops away - e.g. from behind another downstream router).

Determine the Online/Offline state for ethernet connected clients can be an educated guess at best, neither the presence in the lease database, nor in the IPv4 or IPv6 neighbour tables guarantees that a client is actually "online". For wireless, you can use the last received packet timer to see if a client is active (and not just associated to the wifi in sleep mode).

The hostnames can be found in both the lease database and by performing a reverse lookup for the determined IPv4/IPv6 address.


Wow, thanks for your answer. Really comprehensive and exactly what I was looking for. I wasn't aware about the vendor request, but I guess that sounds logical now that I think about it. I'll have a look at each one of them and try put something together. Thanks Jow!