How to get a list of connected clients?
# 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 << "EOF" > /etc/show_wifi_clients.sh #!/bin/sh # /etc/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
For universal driver
cat << "EOF" > /etc/show_wifi_clients.sh #!/bin/sh # /etc/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
Make it executable:
chmod +x /etc/show_wifi_clients.sh
Now run it:
/etc/show_wifi_clients.sh
See also: Wireless Utilities