Skip to content

Instantly share code, notes, and snippets.

@oxavelar
Last active March 16, 2025 13:00
Show Gist options
  • Save oxavelar/5be72dc2b08f7743c0b46c22f4f7a01f to your computer and use it in GitHub Desktop.
Save oxavelar/5be72dc2b08f7743c0b46c22f4f7a01f to your computer and use it in GitHub Desktop.
(
disconnect() {
local dev=$1
local mac=$2
echo "$dev: disconnect $mac" > /dev/kmsg
ubus call hostapd.$dev del_client "{'addr':'$mac', 'reason':8, 'deauth':true, 'ban_time':0}"
}
mt79_rssi_monitor() {
local dev=$1
echo "$dev: watchdog [rssi-monitor]" > /dev/kmsg
(
while true; do
sleep 5
stas=$(iw dev "$dev" station dump | awk 'BEGIN {RS="Station"; ORS="\n"} {gsub(/\n\s/, " "); print $0}')
noise=$(iwinfo "$dev" info | grep -oE 'Noise:\s(-?[0-9]+)' | awk '{print $2}')
echo "${stas}" | while IFS= read -r sta; do
if [ -z "$sta" ]; then continue ;fi
mac=$(echo "${sta}" | grep -oE '([a-f0-9]{2}:){5}[a-f0-9]{2}')
signal=$(echo "${sta}" | grep -oE 'signal:\s*(-?[0-9]+)' | head -n1 | awk '{print $2}')
sensed=$(echo "${sta}" | grep -oE 'inactive time:\s*([0-9]+)' | awk '{print $3}')
if [ "$signal" -lt "$noise" ] &&
[ "$sensed" -gt 10000 ] ||
[ "$sensed" -gt 20000 ]; then
disconnect "$dev" "$mac"
fi
done
done
) &
}
# Ensure necessary services are up
sleep 40
# Start bogus-client monitoring for APs
for dev in $(iwinfo | awk '/phy[0-9]-ap[0-9]/ { print $1 }'); do
mt79_rssi_monitor "$dev" &
done
)
@oxavelar
Copy link
Author

oxavelar commented Dec 8, 2024

If this is working you should see something like this:

[   37.914315] phy0-ap0: watchdog [rssi-monitor]
[   37.914350] phy1-ap0: watchdog [rssi-monitor]

With events following:

[  171.348035] phy0-ap0: disconnect 70:22:FE:9D:3E:E0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment