Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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

たとえば、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
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした