LoginSignup
2
1

More than 5 years have passed since last update.

capinfosコマンドの使い方

Last updated at Posted at 2019-02-17

1 capinfosとは?

tcpdumpやtsharkでキャプチャしたpcapファイルの情報(*)を表示するときに使います。
(*)キャプチャしたパケットのスループットやパケット数

2 環境

VMware Workstation 14 Player上の仮想マシンを使いました。

OS版数
[root@server ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

[root@server ~]# uname -r
3.10.0-693.el7.x86_64

3 インストール方法

インストール方法
[root@server ~]# yum install wireshark

[root@server ~]# capinfos -h
Capinfos 1.10.14 (Git Rev Unknown from unknown)
Prints various information (infos) about capture files.
See http://www.wireshark.org for more information.

4 オプション一覧

[root@server ~]# capinfos -h
Capinfos 1.10.14 (Git Rev Unknown from unknown)
Prints various information (infos) about capture files.
See http://www.wireshark.org for more information.

Usage: capinfos [options] <infile> ...

General infos:
  -t display the capture file type
  -E display the capture file encapsulation
  -H display the SHA1, RMD160, and MD5 hashes of the file
  -k display the capture comment

Size infos:
  -c display the number of packets
  -s display the size of the file (in bytes)
  -d display the total length of all packets (in bytes)
  -l display the packet size limit (snapshot length)

Time infos:
  -u display the capture duration (in seconds)
  -a display the capture start time
  -e display the capture end time
  -o display the capture file chronological status (True/False)
  -S display start and end times as seconds

Statistic infos:
  -y display average data rate (in bytes/sec)
  -i display average data rate (in bits/sec)
  -z display average packet size (in bytes)
  -x display average packet rate (in packets/sec)

Output format:
  -L generate long report (default)
  -T generate table report
  -M display machine-readable values in long reports

Table report options:
  -R generate header record (default)
  -r do not generate header record

  -B separate infos with TAB character (default)
  -m separate infos with comma (,) character
  -b separate infos with SPACE character

  -N do not quote infos (default)
  -q quote infos with single quotes (')
  -Q quote infos with double quotes (")

Miscellaneous:
  -h display this help and exit
  -C cancel processing if file open fails (default is to continue)
  -A generate all infos (default)

Options are processed from left to right order with later options superceeding
or adding to earlier options.

If no options are given the default is to display all infos in long report
output format.

5 時刻情報を表示する方法

5.1 事前準備

キャプチャ用のファイルを作成します。

pcapファイルの作成
[root@server ~]# touch test.cap
[root@server ~]# chmod 664 test.cap
[root@server ~]# ls -l test.cap
-rw-rw-r--. 1 root root 0  2月 17 09:00 test.cap

パケットを10秒間キャプチャします。
なお、tsahrkは、ここ(tsharkコマンドの使い方)を参照してください。

パケットのキャプチャ
[root@server ~]# tshark -i eth0 -a duration:10 -w test.cap
Running as user "root" and group "root". This could be dangerous.
Capturing on 'eth0'
74

キャプチャしたファイルを確認します。

ファイルの確認
[root@server ~]# ls -l test.cap
-rw-rw-r--. 1 root root 21556  2月 17 09:01 test.cap

5.2 ファイルタイプを表示する方法(-t)

キャプチャしたファイルタイプを表示してみます。
ファイルのタイプは、pcapngということがわかります。

実行結果
[root@server ~]# capinfos -t test.cap
File name:           test.cap
File type:           Wireshark/... - pcapng

5.3 カプセル化の方法を表示する方法(-E)

実行結果
[root@server ~]# capinfos -E test.cap
File name:           test.cap
File encapsulation:  Ethernet

5.4 キャプチャファイルのチェックサムを表示する方法(-H)

test.capのチェックサムを表示してみます。

実行結果
[root@server ~]# capinfos -H test.cap
File name:           test.cap
SHA1:                11f019067c09d94e1ea90713bec362d296ed073b
RIPEMD160:           6ef9e247bcdb4ebc8798e0f0c8fc0acb33321307
MD5:                 c90d6341a9935fecee06a838ccd2c152

6 パケット数やパケットサイズの表示方法

6.1 パケット数を表示する方法(-c)

キャプチャしたパケット数を表示してみます。

事前準備(pcapファイルの作成)
[root@server ~]# tcpdump -i eth0 icmp -w test.cap

ここでは、デフォルトGWに対してpingを実行(1回)してみます。
なお、pingの使い方は、ここ(pingコマンドの使い方)を参照してください。

事前準備(pcapファイルの作成)
[root@server ~]# ping -c 1 192.168.3.1

ICMP echo request/echo replyそれぞれが1パケットずつ送信されています。
よって、合計2個のパケットがキャプチャされています。

事前準備(pcapファイルの作成)
[root@server ~]#  tshark -i eth0 -p icmp -w test.cap
Running as user "root" and group "root". This could be dangerous.
Capturing on 'eth0'
2 ^C

capinfosを実行すると、パケットが2個キャプチャされていることがわかります。

実行結果
[root@server ~]# capinfos -c test.cap
File name:           test.cap
Number of packets:   2

6.2 パケットサイズを表示する方法(-d)

キャプチャしたパケットサイズを表示してみます。

実行結果
[root@server ~]# capinfos -d test.cap
File name:           test.cap
Data size:           196 bytes

パケットサイズが196バイトであることがわかります。
パケットサイズは、イーサネットヘッダも含めたサイズになります。
ここでは、ICMP echo request/echo replyそれぞれが1パケットずつ
送信されているので、2つのパケットサイズの合計値になります。

なお、Wiresharkの"Length"欄に表示される値の合計になります。

7 時間に関する情報を表示する方法

7.1 事前準備

パケットを10秒間キャプチャします。

pcapファイルの作成
[root@server ~]# touch test.cap
[root@server ~]# chmod 664 test.cap
[root@server ~]# ls -l test.cap
-rw-rw-r--. 1 root root 0  2月 17 10:08 test.cap

[root@server ~]# tshark -i eth0 -a duration:10 -w test.cap
Running as user "root" and group "root". This could be dangerous.
Capturing on 'eth0'
44

7.2 キャプチャした時間を表示する方法

最初のパケットをキャプチャしてから、キャプチャを終了するまでの時間を表示します。

実行結果
[root@server ~]# capinfos -u test.cap
File name:           test.cap
Capture duration:    9 seconds

ちなみに、以下のようにコマンドを実行して、pingを実行しないと
パケットはキャプチャされません。
そのようなときは、capinfosの実行結果は、n/aと表示されます。

実行結果
[root@server ~]# tshark -i eth0 -p icmp -a duration:10 -w test.cap
Running as user "root" and group "root". This could be dangerous.
Capturing on 'eth0'

[root@server ~]# capinfos -u test.cap
File name:           test.cap
Capture duration:    n/a

8 統計情報を表示する方法

8.1 事前準備

デフォルトGWにpingを0.1秒間隔で実行します。
なお、大量にパケットが送信されるので、まわりに迷惑をかけない環境で実行してください。

[root@server ~]# ping -i 0.1 192.168.3.1

パケットを10秒間キャプチャします。

capファイルの作成
[root@server ~]# tshark -i eth0 -p icmp -a duration:10 -w test.cap
Running as user "root" and group "root". This could be dangerous.
Capturing on 'eth0'
191

8.2 単位時間(秒)あたりのパケットキャプチャ数を表示する方法(-x)

1秒間にキャプチャしたパケット数を表示してみます。

パケットが1秒間に19パケットキャプチャされていることがわかります。
(期待値より1パケット少ないのは誤差かな)

実行結果
[root@server ~]# capinfos -x test.cap
File name:           test.cap
Average packet rate: 19 packets/sec

8.3 スループットを表示する方法(-i)

スループットは15636.80(bits/sec)であることがわかります。

実行結果
[root@server ~]# capinfos -iT test.cap
File name       Data bit rate (bits/sec)
test.cap        15636.80

ただし、どのような計算で上記結果になったのかわかりませんでした。
私は以下のように計算しました。
19(packet) * 98(byte/packet) * 8(bit) = 14,896(bit)

9 おわりに

本コマンドの調査を始める前は、特定の相手とのスループットを
表示できるのではないか?と思っていたのですが、そのようではないようです。
特定の相手とのスループットを表示するには、あらかじめ、その相手とだけの
通信をpcapファイルに用意しておく必要があるようです。少し期待はずれでした。

Z 参考情報

2
1
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
2
1