分享ddwrt tomato路由器剔除信号质量差客户端的脚本

在使用ddwrt tomato路由器配置全屋wifi时,会遇到客户端信号差但不断连的情况,使用以下脚本断开信号较差客户端的连接。

脚本来自https://git.losert.xyz/krypton/Scripts/tree/master

#!/bin/sh

##############################################
# This script disconnects connected clients, # 
# where the signal is below the configured   #
# signal.                                    #
##############################################
# v1.0                                       #
# maintained by Rene Losert <dev@losert.xyz> #
##############################################

# 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值