Last active
January 7, 2020 10:54
-
-
Save walduino/c87c461585eecbbdcb91624a598c3d2b to your computer and use it in GitHub Desktop.
Script to query multiple openwrt access points and check connected clients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# /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 | |
routers="archer swordsman" | |
dhcp_host="swordsman" | |
date +%F_%T | |
dhcpleases=`ssh root@$dhcp_host cat /tmp/dhcp.leases` | |
echo -e "# IP address\tname\tMAC address\tAP" | |
# list all wireless network interfaces | |
# (for universal driver; see wiki article for alternative commands) | |
for routername in $routers; do | |
for interface in `ssh root@$routername iwinfo | grep ESSID | cut -f 1 -s -d" "` | |
do | |
# for each interface, get mac addresses of connected stations/clients | |
maclist=`ssh root@$routername iwinfo $interface assoclist | grep dBm | cut -f 1 -s -d" "` | |
# for each mac address in that list... | |
for mac in $maclist | |
do | |
# if [ "$mac" != "0C:8F:FF:8E:DD:C6" ] || [ "$mac" != "54:F2:01:A0:06:52" ] ; then | |
# break | |
# fi | |
# If a DHCP lease has been given out by dnsmasq, save it. | |
ip="UNKN" | |
host="" | |
ip=`echo "$dhcpleases" | cut -f 2,3,4 -s -d" " | grep -i $mac | cut -f 2 -s -d" "` | |
host=`echo "$dhcpleases" | 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\t$routername" | |
done | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/dersimn/owrtwifi2mqtt