Is there a way to list the connected devices on my wifi access point?

I have an Angstrom Linux device acting as an access point, running hostapd, dhcpd, which works fine. Can I get a list of devices connected to the Wi-Fi? I know I can get the DHCP leases, but I need to know which devices connect through wlan0. I’ve tried this (iwlist has options):

iwlist wlan0 ap
iwlist wlan0 accesspoints
iwlist wlan0 peers

but all return:

wlan0     Interface doesn't have a list of Peers/Access-Points

iwconfig, iwgetid, iwpriv and iwspy are also present in /sbin, but don’t seem to have options to display the client list.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You should use iw dev wlan0 station dump as root

Method 2

You could Use “arp” as root:

$ sudo arp

or:

$ sudo arp | sort

kinda nicer, but you got the point 🙂

Method 3

You can also find list of connected devices to your AP by using this command:

cat /var/lib/misc/dnsmasq.leases

dnsmasq.leases file lists all the devices which connected to AP so far.
Also you can get list of all devices which connected to your device over WiFi or Ethernet by using this command:

sudo arp

Method 4

arp-scan

As said on this answer you can use arp-scan package. Just arp-scan -l.

arp-scan is a command-line tool for system discovery and fingerprinting. It constructs and sends ARP requests to the specified IP addresses, and displays any responses that are received.

With systemd/udev names I found very useful an alias to

sudo arp-scan -l -t 200 -I $(ls /sys/class/net | grep -o "wl[^t]+")

for the wireless interface and en instead of wl for wired interfaces.

  • -I --interface Use network interface . If this option is not specified, arp-scan will search the system interface list for the lowest numbered, configured up interface (excluding loopback).
  • -l --localnet Generate addresses from network interface configuration. Use the network interface IP address and network mask to generate the list of target host addresses.
  • -t --timeout Set initial per host timeout to ms, default=100. This timeout is for the first packet sent to each host.

To read the arp cache table cool kids nowadays use ip neighbor.

Method 5

the accepted answer is of course correct but some systems might be too old (or some drivers) for iw

if you have hostapd you probably also have hostapd_cli, so you can try

hostapd_cli list_sta

I down-voted any answer that was not iw because they rely on traffic actually traversing the link. Getting a list of think connected to your wifi should not depend on those things making higher level (OSI model-wise).

Method 6

I use something like this fast solution:

awk '$4~/[1-9a-f]+/&&$6~/^wl/{print "ip: "$1" mac: "$4}' /proc/net/arp

The /[1-9a-f]/ filter removes MAC addresses like 00:00:00... from listing.

The /^wl/ filter removes all non-wireless interfaces (without “wl” at the beginning of their names).

The example result is:

ip: 192.168.0.1 mac: 64:6e:ea:d1:d3:0a
ip: 192.168.0.2 mac: a0:d3:a1:6d:d0:4a

Also, for my convenience, I use a file macs with list of mac addresses of this context:

90:94:97:9f:85:10 My Huawei
64:6e:ea:d1:d3:0a Rostelecom Router

To get a list of connected devices with parsing this file I use such command (the END section is unnecessary – it’s an updater):

awk 'BEGIN{while((getline<"macs")>0){nmm=$0;gsub($1" ","",nmm);nmz[$1]=nmm}}$4~/[1-9a-f]+/&&$6~/^wl/{print $1 " " (nmz[$4]?nmz[$4]:$4);if(!nmz[$4]){nmz[$4]=$4;update=1}}END{if(update){system("gawk -f macupd.awk")}}' /proc/net/arp

So in this way the result will be:

192.168.0.1 Rostelecom Router
192.168.0.74 My Huawei

The macupd.awk is the script for updating macs file. It gets vendor names from file oui.txt (located in the same directory) and uses them as descriptions of unknown hosts/clients connected to your machine and writes them to the macs list file (you may disable this by removing END section from command). Here is the script:

#!/usr/bin/gawk -f
BEGIN{
    while((getline<"macs")>0){
        str++
        if($0!~"(^#|^$)"){
            nam=$0
            gsub($1" ","",nam)
            macnamz[$1]=nam
        }
    }

    while((getline<"/proc/net/arp")>0){
        if($4~/[1-9a-f]+/&&$6~/^wl/){
            if(!macnamz[$4]){
                mac=macv=$4
                gsub(":","",macv)
                vendor=substr(macv,1,6)
                rs=RS
                RS="n|r"
                while((getline<"oui.txt")>0){
                    if(toupper($1)~toupper(vendor)){gsub(/.*t+/,"");macnamz[mac]=$0;update=1}
                }
                RS=rs
            }
        }
    }
    if(update){
        for(i in macnamz){print i " " macnamz[i] > "macs"}
        print "" > "macs"
    }
}

So if in the first running of my imperfect command the result will be (if all hosts where unknown):

192.168.10.1 00:d0:ef:aa:ee:ff
192.168.10.2 f4:bd:9e:00:00:00
192.168.10.3 00:22:72:11:22:33

The second running will be such:

192.168.10.1 IGT
192.168.10.2 Cisco Systems, Inc
192.168.10.3 American Micro-Fuel Device Corp.

The description of my script.

getline<"macs" – Reading lines from list

if($0!~"(^#|^$)") – Ignoring commented and empty lines.

gsub($1" ","",nam) – I used nam variable for description (everything after space).

macnamz[$1]=nam – Final conversion of line to a part of associative array (there can not be 2 duplicated MACs – 2nd will overwrite 1st).

getline<"/proc/net/arp" – Getting connected IPs and MACs.

if($4~/[1-9a-f]+/&&$6~/^wl/) – Filtering out header line, zero MACs, and non-wireless interfaces.

if(!macnamz[$4]) – If connected device is not registered in our macs file.

gsub(":","",macv) and vendor=substr(macv,1,6) – Getting first 6 symbols of MAC.

RS="n|r" – Because oui.txt may have MS Windows line endings.

gsub(/.*t+/,"") – Removing tabs

macnamz[mac]=$0 – Converting line to an array member.

update=1 – This variable says that updating of file is necessary (if it is).

Method 7

There is also a free (commercial licence, unlimited duration trial with maximum of 5 devices displayed) GUI application, WifiGuard.

Method 8

On Ubuntu, After starting the hotspots by clicking in WiFi top right of screen in gnome, select WiFi and “Wi-Fi Settings”, config opens, select hamburger top right in menu, “Turn On Wi-Fi Hotspot…”

In terminal display connected clients by running in superuser mode :

iw dev wlan0 station dump


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x