Created
October 21, 2022 15:22
-
-
Save amon-ra/42bfee062be2d2d13f89eea9750af532 to your computer and use it in GitHub Desktop.
Openwrt disconect clients with low rsi
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/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 | |
# - add to crontab: crontab -e | |
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 /tmp | 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 | |
else | |
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 "/tmp/angry_wifi_client_${MAC}_$(date +%s)" | |
fi | |
fi | |
done | |
# Remove from the do-not-disconnect list | |
CURDATE=$(date +%s) | |
for FILE in $(find /tmp | 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