how to get a list of the connected wifi clients in OpenWrt 10.03?
5 Answers
In order to see associated wifi clients, even if they don't have a DHCP Client or have no ip, you have to ask the AP for associated wifi devices:
# MAC80211
iw dev wlan0 station dump
# Universal (Tested with OpenWRT 14.07 and 15.05.X)
# iwinfo must be installed first as it is optional
# opkg update && opkg install iwinfo
iwinfo wlan0/wl0/ath0 assoclist
# using hostapd
ubus call hostapd.wlan0 get_clients
# Proprietary Broadcom (wl)
wl -i wl0 assoclist
# Proprietary Atheros (madwifi)
wlanconfig ath0 list sta
This way you will also see the connection speed. For me this is looking like this:
# iwinfo wlan0 assoclist
12:34:56:78:9A:BC -26 dBm / -95 dBm (SNR 69) 1930 ms ago
RX: 24.0 MBit/s, MCS 0, 20MHz 3359 Pkts.
TX: 130.0 MBit/s, MCS 14, 20MHz, short GI 1209 Pkts.
- 303
- 3
- 8
You may use the arp-table, or DHCP-leases. Not a perfect solution, maybe it's enough?
List arp-table
arp
List DHCP-leases
cat /tmp/dhcp.leases
... and combined
for ip in $(arp | grep -v IP | awk '{print $1}'); do
grep $ip /tmp/dhcp.leases;
done
- 375
- 2
- 10
-
3You have recent leases too, like a powered off laptop and a phone currently on another wifi network. – Dereckson Aug 04 '14 at 17:54
-
I still have empty response cat /tmp/dhcp.leases, while many devices got IP and network settings from WIFI of OpenWRT. – Boris Ivanov Aug 19 '17 at 18:25
-
This will not work if your router works as a bridge, since it doesn't offer the DHCP itself. – Raúl Salinas-Monteagudo Nov 28 '18 at 09:49
Instead of cat /tmp/dhcp.leases|wc -l
and arp -a
, my solution is
opkg update
opkg install arp-scan
arp-scan --interface=br-lan --localnet | grep responded | awk '{print $12}'
It will return the number of devices which connected to OpenWRT by LAN port. Almost real time.
- 561
- 4
- 14
How about nmap?
opkg install nmap
Then do a stealth scan of your subnet (likely 192.168.1.0/24)
nmap -sS 192.168.1.0/24
This will list services running on the clients as well. It may also set off alarms if the client has port-scan detecting software (i.e snort) installed so be careful.
- 11
- 1
-
You generate traffic here. If you just want to keep statistics every minute, for example you would be creating traffing, radiation and consumption needlessly. I am thinking about the case where you want to know if your mobile phone is at your place, for a house automation system. You don't want to drain your phone battery for this. – Raúl Salinas-Monteagudo Nov 28 '18 at 09:58
To get them directly from hostapd
(the daemon that manages the access point):
$ ubus call hostapd.wlan0 get_clients
{
"freq": 2462,
"clients": {
"<mac addr 1>": {
"auth": true,
"assoc": true,
"authorized": true,
"preauth": false,
"wds": false,
"wmm": true,
"ht": true,
"vht": false,
"wps": false,
"mfp": false,
"rrm": [
0,
0,
0,
0,
0
],
"aid": 1
}
}
}
(or replace wlan0
with the interface you are interested in)
- 209
- 2
- 7