LoginSignup
8
8

More than 5 years have passed since last update.

tcpdumpでicmpをフィルタする

Last updated at Posted at 2015-12-15

以下のフィルタで、Echo MessageとEcho Reply Messageのみをキャプチャできる。


tcpdump icmp[icmptype] == 0 or icmp[icmptype] == 8

以下参考
https://forum.ivorde.com/tcpdump-how-to-to-capture-only-icmp-ping-echo-requests-t15191.html

2015/12/16 追記

icmp[icmptype]という表記は、icmp[0]と同じ。
[]で指定している内容は、icmpヘッダの中身の、
何バイト目のデータか、ということ。

icmpヘッダの先頭から1バイトが、icmp typeなので、
この値が0x00か0x08を指定すれば、
Echo MessageとEcho Reply Messageのみをフィルタできる。

ちなみに、icmpヘッダの6バイト目から2バイト分を見れば、
シーケンス番号でフィルタも出きる(需要があるかは知らないが)


[root@test1 ~]# tcpdump '( icmp[0] == 0x00 or icmp[0] == 0x08 ) and icmp[6:2] == 0x0001'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:21:49.658584 IP test1.localhost.localdomain > test2.localhost.localdomain: ICMP echo request, id 15404, seq 1, length 64
09:21:49.658765 IP test2.localhost.localdomain > test1.localhost.localdomain: ICMP echo reply, id 15404, seq 1, length 64
^C
2 packets captured
2 packets received by filter
0 packets dropped by kernel
[root@test1 ~]#

※この結果の中の、ホスト名等々はいじってます。

動作見ながら、こんな感じだと思いますが、
勘違い等あれば、突っ込みください。

8
8
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
8
8