16

how to get a list of the connected wifi clients in OpenWrt 10.03?

LanceBaynes
  • 3,237

6 Answers6

21

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.
17

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
nsg
  • 385
3

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.

Alan42
  • 591
  • 4
  • 14
2

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.

2

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)

kirelagin
  • 219
1

If you use OpenWRT on a dumb AP, you might not have IPs as the DHCP server is on the router.

For this purpose I created a small script to present the results in this form:

root@r7800home:/etc/config/scripts# ./show_wifi_clients.sh 
host        host_IP     interface   MAC         SSID        channel width   unit    TX  unit    Station_MAC     RX_lev  unit    TX_rate unit    RX_rate unit
r7800home   192.168.10.42   phy0-ap0    b0:b9:8a:4d:87:fa   monkeys-home    36  80  MHz 23.00   dBm F2:03:35:6D:0E:A3   -78 dBm 866.7   MBit/s  650.0   MBit/s
r7800home   192.168.10.42   phy0-ap0    b0:b9:8a:4d:87:fa   monkeys-home    36  80  MHz 23.00   dBm 4C:53:FD:E3:94:80   -77 dBm 433.3   MBit/s  390.0   MBit/s
r7800home   192.168.10.42   phy0-ap0    b0:b9:8a:4d:87:fa   monkeys-home    36  80  MHz 23.00   dBm 00:F3:61:27:36:8E   -76 dBm 866.7   MBit/s  585.0   MBit/s
r7800home   192.168.10.42   phy0-ap0    b0:b9:8a:4d:87:fa   monkeys-home    36  80  MHz 23.00   dBm 5E:3E:E9:A5:C4:8B   -81 dBm 780.0   MBit/s  24.0    MBit/s
r7800home   192.168.10.42   phy0-ap0    b0:b9:8a:4d:87:fa   monkeys-home    36  80  MHz 23.00   dBm C4:91:0C:B3:C5:00   -86 dBm 433.3   MBit/s  24.0    MBit/s
r7800home   192.168.10.42   phy0-ap0    b0:b9:8a:4d:87:fa   monkeys-home    36  80  MHz 23.00   dBm 40:26:19:B4:69:08   -82 dBm 433.3   MBit/s  24.0    MBit/s
r7800home   192.168.10.42   phy0-ap0    b0:b9:8a:4d:87:fa   monkeys-home    36  80  MHz 23.00   dBm 10:B5:88:6F:97:D6   -85 dBm 650.0   MBit/s  24.0    MBit/s
r7800home   192.168.10.42   phy0-ap0    b0:b9:8a:4d:87:fa   monkeys-home    36  80  MHz 23.00   dBm 3C:A6:F6:33:05:DA   -88 dBm 780.0   MBit/s  24.0    MBit/s
r7800home   192.168.10.42   phy0-ap0    b0:b9:8a:4d:87:fa   monkeys-home    36  80  MHz 23.00   dBm 48:26:2C:96:D7:95   -91 dBm 650.0   MBit/s  24.0    MBit/s
r7800home   192.168.10.42   phy0-ap1    b2:b9:8a:4d:87:fa   monkeys-vf  36  80  MHz 23.00   dBm 4C:77:CB:EF:D2:F1   -70 dBm 866.7   MBit/s  866.7   MBit/s
r7800home   192.168.10.42   phy1-ap0    b0:b9:8a:4d:87:fb   monkeys-iot-30  1   20  MHz 30.00   dBm 2A:FF:01:01:01:27   -59 dBm 1.0 MBit/s  6.0 MBit/s
r7800home   192.168.10.42   phy1-ap0    b0:b9:8a:4d:87:fb   monkeys-iot-30  1   20  MHz 30.00   dBm 9C:9C:1F:8C:BE:D2   -67 dBm 1.0 MBit/s  48.0    MBit/s
r7800home   192.168.10.42   phy1-ap0    b0:b9:8a:4d:87:fb   monkeys-iot-30  1   20  MHz 30.00   dBm 10:CE:02:96:9F:65   -55 dBm 54.0    MBit/s  72.2    MBit/s
r7800home   192.168.10.42   phy1-ap0    b0:b9:8a:4d:87:fb   monkeys-iot-30  1   20  MHz 30.00   dBm 5C:C3:36:2D:F9:D5   -64 dBm 54.0    MBit/s  117.0   MBit/s
r7800home   192.168.10.42   phy1-ap2    b6:b9:8a:4d:87:fb   monkeys-home    1   20  MHz 30.00   dBm 44:91:60:78:34:74   -56 dBm 144.4   MBit/s  24.0    MBit/s

The script is kind of simple and based on the original from the openwrt.org forum:

# cat show_wifi_clients.sh 
#!/bin/sh

echo -e "host\t\thost_IP\t\tinterface\tMAC\t\t\tSSID\t\tchannel\twidth\tunit\tTX\tunit\tStation_MAC\t\tRX_lev\tunit\tTX_rate\tunit\tRX_rate\tunit" host=cat /proc/sys/kernel/hostname ip=ip route get 1.2.3.4 | awk '{print $7}' for interface in iwinfo | grep ESSID | cut -f 1 -s -d&quot; &quot; do maclist=iwinfo $interface assoclist | grep dBm | cut -f 1 -s -d&quot; &quot; ssid=iw $interface info | grep ssid | cut -f 2 -s -d&quot; &quot; channel=iw $interface info | grep channel | cut -f 2 -s -d&quot; &quot; width=iw $interface info | grep channel | cut -f 6 -s -d&quot; &quot; apmac=iw $interface info | grep addr | cut -f 2 -s -d&quot; &quot; txpower=iw $interface info | grep txpower | cut -f 2 -s -d&quot; &quot; for mac in $maclist do signal=iw dev $interface station get ${mac} | grep signal: | grep -v ack | awk -F ' ' '{print $2}' txbitrate=iw dev $interface station get ${mac} |grep &quot;tx bitrate&quot; | awk -F ' ' '{print $3}' txbitrateunit=iw dev $interface station get ${mac} |grep &quot;tx bitrate&quot; | awk -F ' ' '{print $4}' rxbitrate=iw dev $interface station get ${mac} |grep &quot;rx bitrate&quot; | awk -F ' ' '{print $3}' rxbitrateunit=iw dev $interface station get ${mac} |grep &quot;rx bitrate&quot; | awk -F ' ' '{print $4}' echo -e "$host\t$ip\t$interface\t$apmac\t$ssid\t$channel\t$width\tMHz\t$txpower\tdBm\t$mac\t$signal\tdBm\t$txbitrate\t$txbitrateunit\t$rxbitrate\t$rxbitrateunit" done done