Skip to content

Instantly share code, notes, and snippets.

@c4mx
Created August 4, 2020 21:26
Show Gist options
  • Save c4mx/1419a492e2e7bba63431782e3552bf29 to your computer and use it in GitHub Desktop.
Save c4mx/1419a492e2e7bba63431782e3552bf29 to your computer and use it in GitHub Desktop.
OpenWrt show connected clients
#!/bin/sh
# show_wifi_clients.sh
# Shows MAC, IP address and any hostname info for all connected wifi devices
# modification based on https://openwrt.org/faq/how_to_get_a_list_of_connected_clients
echo "# All connected wifi devices, with IP address,"
echo "# hostname (if available), and MAC address."
printf "%-15s %-15s %15s\n" "IP address" "Host" "MAC"
# 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
echo "${interface}:"
# 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" "`
# When $host = *
echo "$host" | grep -E '^\*$' > /dev/null && host="N/A"
# ... show the mac address:
printf "%-15s %-15s %15s\n" $ip $host $mac
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment