Openwrt局域网设备测速脚本

#!/bin/sh
echo "Collecting data..."
cat /proc/net/arp | grep : | grep ^192 | grep -v 00:00:00:00:00:00 | awk '{print $1}' > mac-ip
iptables -N UPLOAD
iptables -N DOWNLOAD
while read line;do iptables -I FORWARD 1 -s $line -j UPLOAD;done < mac-ip
while read line;do iptables -I FORWARD 1 -d $line -j DOWNLOAD;done < mac-ip
sleep 1
echo "Download speed:"
iptables -nvx -L FORWARD | grep DOWNLOAD | awk '{print $2/1024/1" KB/s ",$1/10" packets/s", $9}' | sort -n -r
echo ""
echo "Upload speed:"
iptables -nvx -L FORWARD | grep UPLOAD | awk '{print $2/1024/1" KB/s ",$1/10" packets/s", $8}' | sort -n -r
 
while read line;do iptables -D FORWARD -s $line -j UPLOAD;done < mac-ip
while read line;do iptables -D FORWARD -d $line -j DOWNLOAD;done < mac-ip
iptables -X UPLOAD
iptables -X DOWNLOAD

上面代码保存为sh文件并给予执行权限然后运行即可

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注