借鉴了https://www.cnblogs.com/jzyuchen/p/3939985.html
新建一个shell脚本
vim wa.sh
按下i之后输入
#!/bin/sh
#iptables -F
#iptables -X UPLOAD
#iptables -X DOWNLOAD
stopflag=0
delr(){
echo "ctrl-c"
let stopflag=1
iptables -X UPLOAD
iptables -X DOWNLOAD
clear
#exit 0
}
trap "delr" INT #ctrl-c
trap "delr" HUP #hup
trap "delr" QUIT #ctrl-\
trap "delr" ABRT #err
trap "delr" ALERM #tiomeout
trap "delr" TERM #shutdown
clear
echo "Collecting data..."
echo ""
showinfo(){
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
clear
echo "Download speed:"
echo ""
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:"
echo ""
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
}
while [ $stopflag -eq 0 ]
do
#echo "hello"
showinfo
#sleep 1
done
按esc退出编辑
输入:wq保存退出
chmod +x ./wa.sh赋予执行权限
./wa.sh运行
每隔一秒会自动刷新,显示每个IP对应的网速
按下ctrl+c退出