User Tools

Site Tools


playground:faq:how_to_get_a_list_of_connected_clients

How to get a list of connected clients?

Wireless Utilities

# Proprietary Broadcom (wl)
wl -i wl0 assoclist
 
# Proprietary Atheros (madwifi)
wlanconfig ath0 list sta
 
# MAC80211
iw dev wlan0 station dump
 
# Universal
iwinfo wlan0/wl0/ath0 assoclist

A script that uses the above to display MAC address, and DHCP lease information (IP address, hostname):

For MAC80211 driver

cat > /etc/config/show_wifi_clients.sh << "EOF_DOCUMENT"
#!/bin/sh
 
# /etc/config/show_wifi_clients.sh
# Shows MAC, IP address and any hostname info for all connected wifi devices
# written for openwrt 12.09 Attitude Adjustment
 
echo    "# All connected wifi devices, with IP address,"
echo    "# hostname (if available), and MAC address."
echo -e "# IP address\tname\tMAC address"
# list all wireless network interfaces 
# (for MAC80211 driver; see wiki article for alternative commands)
for interface in `iw dev | grep Interface | cut -f 2 -s -d" "`
do
  # for each interface, get mac addresses of connected stations/clients
  maclist=`iw dev $interface station dump | grep Station | cut -f 2 -s -d" "`
  # for each mac address in that list...
  for mac in $maclist
  do
    # If a DHCP lease has been given out by dnsmasq,
    # save it.
    ip="UNKN"
    host=""
    ip=`cat /tmp/dhcp.leases | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 2 -s -d" "`
    host=`cat /tmp/dhcp.leases | cut -f 2,3,4 -s -d" " | grep $mac | cut -f 3 -s -d" "`
    # ... show the mac address:
    echo -e "$ip\t$host\t$mac"
  done
done
EOF_DOCUMENT

For universal driver

cat > /etc/config/show_wifi_clients.sh << "EOF_DOCUMENT"
#!/bin/sh
 
# /etc/config/show_wifi_clients.sh
# Shows MAC, IP address and any hostname info for all connected wifi devices
# written for openwrt 12.09 Attitude Adjustment
 
echo    "# All connected wifi devices, with IP address,"
echo    "# hostname (if available), and MAC address."
echo -e "# IP address\tname\tMAC address"
# list all wireless network interfaces
# (for universal driver; see wiki article for alternative commands)
for interface in `iwinfo | grep ESSID | cut -f 1 -s -d" "`
do
  # for each interface, get mac addresses of connected stations/clients
  maclist=`iwinfo $interface assoclist | grep dBm | cut -f 1 -s -d" "`
  # for each mac address in that list...
  for mac in $maclist
  do
    # If a DHCP lease has been given out by dnsmasq,
    # save it.
    ip="UNKN"
    host=""
    ip=`cat /tmp/dhcp.leases | cut -f 2,3,4 -s -d" " | grep -i $mac | cut -f 2 -s -d" "`
    host=`cat /tmp/dhcp.leases | cut -f 2,3,4 -s -d" " | grep -i $mac | cut -f 3 -s -d" "`
    # ... show the mac address:
    echo -e "$ip\t$host\t$mac"
  done
done
EOF_DOCUMENT

Make it executable:

chmod ugo+rx /etc/config/show_wifi_clients.sh

Now run it:

/etc/config/show_wifi_clients.sh
playground/faq/how_to_get_a_list_of_connected_clients.txt · Last modified: 2018/07/08 19:14 by tmomas