如何获取过去30秒内丢弃的数据包数

时间:2016-07-14 13:04:51

标签: bash iptables

我正在以编程方式在具有IP表规则的接口上丢弃数据包(丢弃以50%概率进入的数据包)。我希望能够使用bash脚本获取过去3秒内丢弃的数据包数量。我已经看过ifstat,但它似乎并没有意识到正在发生丢弃(也许它只是在查看通过IPtables后进入的数据包?)。是否有其他工具或实用工具可以用来获得这样的数字?

编辑:我应该提到iptables是我用来模拟高速网络的工具,它可以使收件人由于数量庞大而开始丢弃数据包。这种情况是我想要看到并能够识别的。

2 个答案:

答案 0 :(得分:3)

使用dumpcap:

dumpcap  -i your_interface_here -a duration:3 -w log.pcap | grep '^Packets received/dropped'

dumpcap manpage says:

  

-a
             指定一个标准,指定Dumpcap何时停止写入              到捕获文件。标准是形式测试:值,其中              测试是以下之一:

       duration:value Stop writing to a capture file after value seconds
       have elapsed.
     

-i
   捕获接口
  -w
             将原始数据包数据写入outfile。

答案 1 :(得分:0)

您可以尝试ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); mForecastAdapter = new ArrayAdapter<String>( //The current context (current activity) getActivity(), //ID of list item layout R.layout.list_item_forecast, //id of the textView to populate R.id.list_item_forecast_textview, //data to populate weekForecast ); listView.setAdapter(mForecastAdapter); ,它通过iptable规则显示丢弃的数据包计数。

iptables -vL

规则代表iptables中定义的规则。

相关问题