加入iptables的总字节 [英] add total bytes in iptables
本文介绍了加入iptables的总字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何通过行添加grep的输出编号一致。
how can I add grep output number line by line.
我从
pkts bytes target prot opt in out source destination
0 0 RETURN 0 -- * * 0.0.0.0/0 192.168.1.117
0 0 RETURN 0 -- * * 192.168.0.1 0.0.0.0/0
0 0 RETURN 0 -- * * 0.0.0.0/0 192.168.0.1
375993 19581223 RETURN 0 -- * * 192.168.1.136 0.0.0.0/0
752537 1043650417 RETURN 0 -- * * 0.0.0.0/0 192.168.1.136
123 9348 RETURN 0 -- * * 192.168.1.100 0.0.0.0/0
121 9196 RETURN 0 -- * * 0.0.0.0/0 192.168.1.100
我要添加的所有字节为每个IP地址,并将其存储作为进一步计算变量。
I want to add all bytes for each IP address and store it as variable for further calculation.
iptables -L RRDIPT -vnx -t filter | grep "192.168.1" | cut -d " " -f4
给我的空白和19581223,1043650417,9348和9196,但我在努力增加产量。
gives me the blanks and 19581223,1043650417,9348 and 9196 but I am struggling to add the output.
任何人都可以指导我?
推荐答案
下面的脚本每相吻合起来的字节数的目标IP 的。如果你每次想的源IP 的再修改 $共9
到 $ 8个
The following script tallies up the byte counts per destination IP. If you want per source IP then change the $9
to $8
iptables -L ... | awk '!/destination/{a[$9]+=$2}END{for(item in a)printf("%s\tTotal bytes: %s\n",item,a[item])}'
输入
pkts bytes target prot opt in out source destination
0 1 RETURN 0 -- * * 0.0.0.0/0 192.168.1.117
0 2 RETURN 0 -- * * 192.168.0.1 0.0.0.0/0
0 3 RETURN 0 -- * * 0.0.0.0/0 192.168.0.1
0 4 RETURN 0 -- * * 0.0.0.0/0 192.168.1.117
0 5 RETURN 0 -- * * 192.168.0.1 0.0.0.0/0
0 6 RETURN 0 -- * * 0.0.0.0/0 192.168.1.117
0 7 RETURN 0 -- * * 192.168.0.1 0.0.0.0/0
输出
192.168.0.1 Total bytes: 3
0.0.0.0/0 Total bytes: 14
192.168.1.117 Total bytes: 11
这篇关于加入iptables的总字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文