Last active
November 10, 2025 19:22
-
-
Save rany2/52232f6d71d66181a9c263205e422598 to your computer and use it in GitHub Desktop.
OpenWRT assoclist for all WiFi interfaces
This file contains hidden or 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/sh | |
| . /usr/share/libubox/jshn.sh | |
| list_ifaces() { | |
| ubus list 'hostapd.*' 2>/dev/null | sed 's/^hostapd\.//' | sort -n | |
| } | |
| to_mbps() { | |
| awk -v r="$1" 'BEGIN{if (r=="") {print "N/A"} else {printf "%.1f MBit/s", r/100000}}' | |
| } | |
| for ifname in $(list_ifaces); do | |
| echo "-------------------------------------" | |
| printf ' Stations on: %-16s\n' "$ifname" | |
| echo "-------------------------------------" | |
| json="$(ubus call "hostapd.$ifname" get_clients 2>/dev/null || echo '{}')" | |
| json_init | |
| if ! json_load "$json" 2>/dev/null; then | |
| echo | |
| continue | |
| fi | |
| if ! json_select clients 2>/dev/null; then | |
| echo | |
| continue | |
| fi | |
| json_get_keys macs | |
| [ -z "$macs" ] && { echo; continue; } | |
| for mac in $macs; do | |
| json_select "$mac" 2>/dev/null || continue | |
| json_get_var sig signal | |
| json_select packets 2>/dev/null | |
| json_get_var rx_pkts rx | |
| json_get_var tx_pkts tx | |
| json_select .. | |
| json_select rate 2>/dev/null | |
| json_get_var rx_rate_raw rx | |
| json_get_var tx_rate_raw tx | |
| json_select .. | |
| json_select .. | |
| mac_uc="$(echo "$mac" | tr '[a-f]' '[A-Z]' | sed -e 's/_/:/g')" | |
| sig="${sig:--127}" | |
| rx_bitrate="$(to_mbps "$rx_rate_raw")" | |
| tx_bitrate="$(to_mbps "$tx_rate_raw")" | |
| printf "%s %4s dBm | RX: %-14s %8s Pkts. | TX: %-14s %8s Pkts.\n" \ | |
| "$mac_uc" "$sig" \ | |
| "${rx_bitrate:-N/A}" "${rx_pkts:-0}" \ | |
| "${tx_bitrate:-N/A}" "${tx_pkts:-0}" | |
| done | |
| printf '\n' | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment