可以利用iptable来实现的,看附件的脚本。
把他放到路由器里面,然后运行。
#!/bin/sh
echo "Collecting data..."
echo ""
cat /proc/net/arp | grep : | grep ^ | grep -v :::::| awk '{print $1}'> mac-arp
iptables -N UPLOAD
iptables -N DOWNLOAD
while read line;do iptables -I FORWARD -s $line -j UPLOAD;done < mac-arp
while read line;do iptables -I FORWARD -d $line -j DOWNLOAD;done < mac-arp sleep 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-arp
while read line;do iptables -D FORWARD -d $line -j DOWNLOAD;done < mac-arp
iptables -X UPLOAD
iptables -X DOWNLOAD
iptable