5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tsharkとawkでパケット数とペイロード総量を算出

Posted at

こういう小技は普段使わないせいですぐ忘れてしまうからメモ。

たとえば、xx.xx.xx.xx:xxx -> 192.168.0.20:12345というUDPトラフィックをざっくりキャプチャしてあるとして、この中から特定のフロー192.168.0.10:xxx -> 192.168.0.20:12345について、そのパケット数とペイロードを算出したい、という場合の手順。

手順

# tcpdump -s0 -w /tmp/udp.pcap udp port 12345

# tshark -r /tmp/udp.pcap -T fields -e data.len "ip.src==192.168.0.10"|awk '{pkts+=1; bytes+=$1} END {print "packets=", pkts, "bytes=", bytes}'
packets= 21734 bytes= 22255616

仕組みのメモ

やっていることは単純。-T fields -e XXXで特定のフィールドだけを表示させることができる。たとえば

# tshark -r /tmp/udp.pcap -T fields -e data.len -c 3
1024
1024
1024

とか

tshark -r /tmp/udp.pcap -T fields -e ip.src_host -c 3
192.168.0.10
192.168.0.11
192.168.0.10
5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?