* tcpdumpコマンド [#ja921123]

** 使用可能なネットワークカードを調べる [#n8f81ca4]
 $ sudo tcpdump -D
 $ tcpdump -D
 1.usbus0
 2.em0
 3.usbus1
 4.lo0

** 使用例 [#j1f5467c]
あるサーバからあるウェブサーバへのHTTPリクエストのパケットをダンプし、通信内容を確認する。

*** 1.テスト用のHTMLファイルを作成する [#b96de752]
以下のようにして、test.htmlとして保存する。
 <html>
  <body>
    <form action="http://192.168.100.10/" method="post">
      <input name="FOO" type="hidden" value="BAR" />
      <input type="submit" value="submit" />
    </form>
  </body>
 </html>

*** 2. tcpdumpコマンドを実行し、パケットを監視する [#bed86f09]
 sudo tcpdump -X -i eth0 dst 192.168.100.10

*** 3. w3mコマンドでテスト用のHTMLファイルを開き、HTTPリクエストを実行する [#bc614d24]
 w3m test.html

*** 4. パケット内容を確認する [#acffe685]
 0x0020:  5018 ffff 4d70 0000 504f 5354 202f 2048  P...Mp..POST./.H
 0x0030:  5454 502f 312e 300d 0a55 7365 722d 4167  TTP/1.0..User-Ag
 0x0040:  656e 743a 2077 336d 2f30 2e35 2e33 0d0a  ent:.w3m/0.5.3..
 0x0050:  4163 6365 7074 3a20 7465 7874 2f68 746d  Accept:.text/htm
 0x0060:  6c2c 2074 6578 742f 2a3b 713d 302e 352c  l,.text/*;q=0.5,
 0x0070:  2069 6d61 6765 2f2a 0d0a 4163 6365 7074  .image/*..Accept
 0x0080:  2d45 6e63 6f64 696e 673a 2067 7a69 702c  -Encoding:.gzip,
 0x0090:  2063 6f6d 7072 6573 732c 2062 7a69 702c  .compress,.bzip,
 0x00a0:  2062 7a69 7032 2c20 6465 666c 6174 650d  .bzip2,.deflate.
 0x00b0:  0a41 6363 6570 742d 4c61 6e67 7561 6765  .Accept-Language
 0x00c0:  3a20 656e 3b71 3d31 2e30 0d0a 486f 7374  :.en;q=1.0..Host
 0x00d0:  3a20 3231 392e 3131 392e 3133 362e 3334  :.192.168.100.10
 0x00e0:  0d0a 436f 6e74 656e 742d 7479 7065 3a20  ..Content-type:.
 0x00f0:  6170 706c 6963 6174 696f 6e2f 782d 7777  application/x-ww
 0x0100:  772d 666f 726d 2d75 726c 656e 636f 6465  w-form-urlencode
 0x0110:  640d 0a43 6f6e 7465 6e74 2d6c 656e 6774  d..Content-lengt
 0x0120:  683a 2037 0d0a 0d0a 464f 4f3d 4241 520d  h:.7....FOO=BAR.
 0x0130:  0a                                       .

FOO=BARの文字列が確認できる。

*** 参考 [#d55c0cb7]
http://itpro.nikkeibp.co.jp/article/COLUMN/20070403/267311/

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS