Last active
March 29, 2023 02:45
-
-
Save rampageX/2ef809ff98f94046525fa043d092de20 to your computer and use it in GitHub Desktop.
auto disconnects clients with a low signal strength on DD-WRT / Tomato
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 | |
| ############################################## | |
| # This script disconnects connected clients, # | |
| # where the signal is below the configured # | |
| # signal. # | |
| ############################################## | |
| # v1.0 # | |
| # maintained by Rene Losert <[email protected]> # | |
| ############################################## | |
| # https://git.losert.xyz/krypton/Scripts/tree/master | |
| DEV=$(nvram show 2>&1 |grep ifname|grep 'wl[01]'|cut -d"=" -f2) # Defines the wlan interfaces (usally 2,4GHz & 5 GHz) | |
| SIGNAL="-80" # The Signal threshold, clients below get disconnected | |
| EXCLUDE="38:D5:47:62:F8:7A" # build an exclude for a wlan repeater | |
| key="$1" # get first parameter (currently only for debugging) | |
| if [[ "$key" == "-d" ]]; then | |
| echo "Signal Threshold: $SIGNAL" | |
| echo "Connected Clients:" | |
| fi | |
| while true; do | |
| date=$(date +"%a %b %e %H:%M:%S %Z %Y") | |
| for current in $DEV; do # for loop, for each wifi device (usaly this loop runs two times) | |
| CLIENTS=$(/usr/sbin/wl -a $current assoclist) # get the mac address of all connected clients at the current interface | |
| for MAC in $CLIENTS; do # for loop for each client (MAC) | |
| if [ $MAC != "assoclist" ]; then # the first line of assoclist, is indeed 'assoclist' which of course isn't a client ;-) | |
| SIG=$(/usr/sbin/wl -a $current rssi $MAC) # get the signal strengh of the current client | |
| if [[ "$key" == "-d" ]]; then echo "MAC: $MAC, Signal: $SIG"; fi # Printing client and signal strengh if in debugging mode | |
| if [[ ! "$MAC" = "$EXCLUDE" ]]; then # Proceed only, if client shouldn't be excluded | |
| if [ $SIG -lt $SIGNAL ]; then # Proceed if signal strengh is lower than configured signal threshold | |
| if [[ "$key" == "-d" ]]; then echo "$date: BELOW! Sending deauth to $MAC"; fi # further debugging output | |
| echo "$date: BELOW! Sending deauth to $MAC" >> /tmp/cleanup.log # Log all disconnects | |
| /usr/sbin/wl -a $current deauthenticate $MAC # Finally disconnect client | |
| fi # endif signal of client lower then threshold | |
| fi # endif exclude client | |
| fi #endif mac!=assoclist | |
| done # end loop for all connected clients | |
| done # end loop for interfaces | |
| if [[ "$key" == "-d" ]]; then echo "-----------------------------------"; fi | |
| #echo $date >> /tmp/cleanup.log | |
| sleep 5 | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment