2013-04-10 28 views
0

我想排序并计算从我的服务器上下载多少文件(3种类型)。如何在Linux上嗅探结果进行解析?

我安装tshark跑遵循命令应该捕获GET请求:

`./tshark 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -R'http.request.method == "GET"'` 

所以嗅探器开始工作,每一秒,我得到新的行,这里是一个结果:

0.000000 144.137.136.253 -> 192.168.4.7 HTTP GET /pids/QE13_593706_0.bin HTTP/1.1 
8.330354 1.1.1.1 -> 2.2.2.2 HTTP GET /pids/QE13_302506_0.bin HTTP/1.1 
17.231572 1.1.1.2 -> 2.2.2.2 HTTP GET /pids/QE13_382506_0.bin HTTP/1.0 
18.906712 1.1.1.3 -> 2.2.2.2 HTTP GET /pids/QE13_182406_0.bin HTTP/1.1 
19.485199 1.1.1.4 -> 2.2.2.2 HTTP GET /pids/QE13_302006_0.bin HTTP/1.1 
21.618113 1.1.1.5 -> 2.2.2.2 HTTP GET /pids/QE13_312106_0.bin HTTP/1.1 
30.951197 1.1.1.6 -> 2.2.2.2 HTTP GET /nginx_status HTTP/1.1 
31.056364 1.1.1.7 -> 2.2.2.2 HTTP GET /nginx_status HTTP/1.1 
37.578005 1.1.1.8 -> 2.2.2.2 HTTP GET /pids/QE13_332006_0.bin HTTP/1.1 
40.132006 1.1.1.9 -> 2.2.2.2 HTTP GET /pids/PE_332006.bin HTTP/1.1 
40.407742 1.1.2.1 -> 2.2.2.2 HTTP GET /pids/QE13_452906_0.bin HTTP/1.1 

什么我需要做的是将结果类型存储到其他文件中,并将其计数为/pids/*****.bin。 在Linux不强,但确保它可以完成1-3行脚本。

也许与awk,但我不知道是什么技术来读取嗅探器的结果。

谢谢,

回答

2

难道你不能只是grep的Web服务器的日志文件?

无论如何,HTTP流量相对捕获的线解压到你的服务器的文件,只是

./tshark 'tcp port 80 and \ 
      (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' \ 
      -R'http.request.method == "GET"' | \ 
    egrep "HTTP GET /pids/.*.bin" 
+0

肯定尝试,我可以分析日志,但有时我得到10-20G文件大小,它会导致高中央处理器。所以我试图嗅探它 – 2013-04-10 15:02:35

+0

只是像这样解析输出'tail -f/path/logfile |如果你需要从现在开始的数据'grep etc' – 2013-04-10 15:06:06