Skip to content

Instantly share code, notes, and snippets.

@rampageX
Forked from lg/angry_wifi.sh
Created March 5, 2020 09:41
Show Gist options
  • Save rampageX/296f136296aebe651abc2f3e277df095 to your computer and use it in GitHub Desktop.
Save rampageX/296f136296aebe651abc2f3e277df095 to your computer and use it in GitHub Desktop.
auto disconnects clients with a low signal strength on LEDE / OpenWRT
#!/bin/ash
#
# angry_wifi.sh
#
# auto disconnects clients with a low signal strength on LEDE / OpenWRT. great
# for clients who hold onto a lower-signal-strength accesspoint instead of
# roaming. before running, make sure to download the latest MAC addresses with:
#
# wget --no-check-certificate -O - 'https://services13.ieee.org/RST/standards-ra-web/rest/assignments/download/?registry=MAC&text=apple' | cut -d, -f2 > apple_mac_addresses
#
# some notes:
# - only Apple clients will be disconnected
# - clients won't be re-disconnected for 1 minute if they end up re-connecting
# - be careful with this script, if you don't have solid wifi everywhere clients
# will constantly be disconnected
IFS=$'\n'
while true; do
for LINE in $(iwinfo wlan0 assoclist | grep SNR); do
MAC=$(echo "$LINE" | awk '{ print $1 }')
SIGNAL=$(echo "$LINE" | awk '{ print $2 }')
MAC_PREFIX=$(echo "$MAC" | sed -e 's/://g' | cut -c1-6)
if [ "$SIGNAL" -lt "-80" ]; then
if find . | grep "angry_wifi_client_$MAC" > /dev/null; then
date ; logger -s -t angry_wifi "Low signal client $MAC ($SIGNAL) is back, not disconnecting yet."
# Only allow Apple devices to roam
elif grep "$MAC_PREFIX" apple_mac_addresses; then
date ; logger -s -t angry_wifi "Low signal client $MAC ($SIGNAL) being disconnected."
ubus call hostapd.wlan0 del_client "{'addr':'$MAC', 'reason':5, 'deauth':false, 'ban_time':0}"
# Add to do-not-disconnect list
touch "angry_wifi_client_${MAC}_$(date +%s)"
fi
fi
done
# Remove from the do-not-disconnect list
CURDATE=$(date +%s)
for FILE in $(find . | grep angry_wifi_client); do
TIME=$(echo "$FILE" | cut -d'_' -f 5)
TIME_SINCE=$((CURDATE - TIME))
MAC=$(echo "$FILE" | cut -d'_' -f 4)
if [ "$TIME_SINCE" -gt "60" ]; then
date ; logger -s -t angry_wifi "Low signal client $MAC removed from do-not-disconnect."
rm "$FILE"
fi
done
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment