Openwrt获取客户端实时流量脚本修改

Openwrt获取客户端实时流量脚本修改, 改成以下的。

#!/bin/sh
echo "Collecting data..."
echo "<br>"
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
sleep 1
while read line;do iptables -I FORWARD 1 -d $line -j DOWNLOAD;done < mac-ip
sleep 1 
echo "Download speed:"
echo "<br>"
iptables -nvx -L FORWARD | grep DOWNLOAD | awk '{print $2/1024/1" KB/s ",$1/10" packets/s", $9}' | sort -n -r|grep -v '0 packets/s'
echo "<br>"
echo "Upload speed:"
echo "<br>"
iptables -nvx -L FORWARD | grep UPLOAD | awk '{print $2/1024/1" KB/s ",$1/10" packets/s", $8}' | sort -n -r|grep -v '0 packets/s'

while read line;do iptables -D FORWARD -s $line -j UPLOAD;done < mac-ip
echo "<br>"
sleep 1
while read line;do iptables -D FORWARD -d $line -j DOWNLOAD;done < mac-ip
iptables -X UPLOAD
iptables -X DOWNLOAD

加了两句sleep 1 , 和过滤 grep -v ‘0 packets/s’ 零数据包的, 但如果脚本中断,还会残留iptable的规则的,
需再执行: while read line;do iptables -D FORWARD -d $line -j DOWNLOAD;done < mac-ip

有时间还要再改进一下,加上判断,改善那个残留规则的问题。

关于无聊人

一个无聊人而已
此条目发表在技术生活分类目录。将固定链接加入收藏夹。

One Response to Openwrt获取客户端实时流量脚本修改

  1. QAQ说:

    您好,请问iptables规则残留问题解决了吗?

发表评论

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