2012-02-11 75 views
33

捕獲所有的HTTP數據包我想運行tcpdump一些參數(仍然不知道有什麼用)。然後加載這個stackoverflow.com頁面。如何使用tcpdump的

輸出應該是HTTP通信。後來我想用它作爲shell腳本。所以每當我要檢查一個網站site.com的HTTP江西通信我只可以運行script.sh site.com

HTTP通信應該足夠簡單。如下。

GET /questions/9241391/how-to-capture-all-the-http-communication-data-using-tcp-dump 
Host: stackoverflow.com 
... 
... 

HTTP/1.1 200 OK 
Cache-Control: public, max-age=60 
Content-Length: 35061 
Content-Type: text/html; charset=utf-8 
Expires: Sat, 11 Feb 2012 15:36:46 GMT 
Last-Modified: Sat, 11 Feb 2012 15:35:46 GMT 
Vary: * 
Date: Sat, 11 Feb 2012 15:35:45 GMT 


.... 
decoded deflated data 
.... 

現在,你能告訴我用tcpdump哪個選項來捕獲它嗎?

+1

看起來像 「捲曲-v site.com」 是你所需要的。 :) – 2015-08-05 14:43:04

回答

87

它可以通過ngrep

ngrep -q -d eth1 -W byline host stackoverflow.com and port 80 
    ^^  ^  ^  
     | |  |   | 
     | |  |   | 
     | |  |   v 
     | |  |   filter expression 
     | |  |   
     | |  +--> -W is set the dump format ("normal", "byline", "single", "none") 
     | | 
     | +----------> -d is use specified device instead of the pcap default 
     | 
     +-------------> -q is be quiet ("don't print packet reception hash marks") 
+1

注意:對於那些使用通過在OS X 10.9.x/Mavericks中沖泡安裝的ngrep 1.45,可能會導致「分段錯誤:11」。 jfarcand這裏找到一個解決辦法:https://gist.github.com/jfarcand/8302675和工作對我來說:'的ngrep -q -W署名-d EN0「」「主機some_hostname和端口80''。 – 2014-08-12 21:49:24

+8

ASCII藝術的Thumbup。 – neevek 2015-08-07 04:18:44

19

根據你所提到的情況,的ngrep(在UNIX上)和提琴手(Windows)中可能會更好/更容易的解決方案。

如果你絕對要使用tcpdump的,請嘗試以下選項

 
tcpdump -A -vvv host destination_hostname 

-A (ascii) 
-vvv (verbose output)