实现思路:
读取arp文件,列出所有客户的MAC,然后把用户增加到UPLOAD和DOWNLOAD的target中,隔一秒后读取target中流量信息。
#!/bin/sh echo "Collecting data..." echo "" 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:" 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
本站的文章和资源来自互联网或者站长的原创,按照 CC BY -NC -SA 3.0 CN协议发布和共享,转载或引用本站文章应遵循相同协议。如果有侵犯版权的资 源请尽快联系站长,我们会在24h内删除有争议的资源。欢迎大家多多交流,期待共同学习进步。