41

我想tcpdump用一些参数运行(还是不知道用什么),然后加载stackoverflow.com页面。

输出应该是 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来捕获它?

4

3 回答 3

94

它可以通过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")
于 2012-03-28T09:13:29.847 回答
20

根据您提到的内容,ngrep(在 Unix 上)和 Fiddler(Windows)可能是更好/更简单的解决方案。

如果您绝对想使用 tcpdump,请尝试以下选项

tcpdump -A -vvv 主机destination_hostname

-A(ASCII)
-vvv(详细输出)
于 2012-02-12T03:08:17.203 回答
0
tcpdump -i eth0 -w dump3.pcap -v  'tcp and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'

see http://www.tcpdump.org/manpages/tcpdump.1.html

于 2016-01-21T08:00:20.127 回答