User Tools

Site Tools


playground:faq:how_to_get_a_list_of_connected_clients

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

playground:faq:how_to_get_a_list_of_connected_clients [2018/07/08 19:14] (current)
tmomas created
Line 1: Line 1:
 +====== How to get a list of connected clients? ======
 +
 +->​[[docs:​guide-user:​network:​wifi:​wireless-tool:​wireless.utilities|Wireless Utilities]]
 +
 +<code bash>
 +# 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
 +</​code>​
 +
 +
 +A script that uses the above to display MAC address, and DHCP lease information (IP address, hostname):
 +
 +For MAC80211 driver
 +<code bash>
 +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
 +</​code>​
 +
 +For universal driver
 +<code bash>
 +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
 +</​code>​
 +Make it executable:
 +<code bash>
 +chmod ugo+rx /​etc/​config/​show_wifi_clients.sh
 +</​code>​
 +
 +Now run it:
 +<code bash>
 +/​etc/​config/​show_wifi_clients.sh
 +</​code>​
 +
 +
 +{{tag>​faq wireless}}
  
playground/faq/how_to_get_a_list_of_connected_clients.txt · Last modified: 2018/07/08 19:14 by tmomas