0

我一直在尝试计算我的机器每分钟接收 ICMP 请求的频率。

我尝试使用 tcpdump 并将结果保存到文本文件中,然后 grepping 时间戳以计算它们之间的差异,但这只会导致很多延迟。

我的方法是:

tcpdump -i eth1 icmp[0]==8 | tee abc.txt
grep -Eo '^[^ ]+' abc.txt
perl -e 'open$T,pop;while(1){while(<$T>){ ++$f{$_}>10 and print "[$f{$_}]$_" for /(\d+:\d+)/ }sleep 1;seek $T,0,1}' abc.txt

有没有办法计算在我的机器上接收到 ICMP 请求的频率而不使用任何文件?

我正在从一台机器 ping 到另一台机器,并想计算在接收端接收到 ping 的频率。

4

2 回答 2

1

您可以将 tcpdump 包装在脚本中,不涉及任何文件。注意-ltcpdump 的选项,它说做行缓冲。如果你把它排除在外,你会得到缓冲的输出,这可能不是你想要的。

sout = IO.popen("sudo  tcpdump -l -i any icmp[0]==8 2>&1")
line = sout.gets
while (!line.nil?) 
  p line
  #fiddle with line and do time
  line = sout.gets
end
于 2013-07-15T20:34:04.133 回答
0

您不需要捕获和分析数据包。内核导出计数器/proc/net/snmp

于 2013-07-15T21:34:15.683 回答