標籤:http 使用 os 檔案 資料 2014 ar linux
在Linux下,當我們需要抓取網路資料包分析時,通常是使用tcpdump抓取網路raw資料包存到一個檔案,然後下載到本地使用wireshark介面網路分析工具進行網路包分析。
最近才發現,原來wireshark也提供有Linux命令列工具-tshark。tshark不僅有抓包的功能,還帶瞭解析各種協議的能力。下面我們以兩個執行個體來介紹tshark工具。
1、安裝方法
CentOS: yum install -y wireshark
Ubuntu: apt-get install -y tshark
2、即時列印當前http請求的url(包括網域名稱)
tshark -s 512 -i eth0 -n -f ‘tcp dst port 80‘ -R ‘http.host and http.request.uri‘ -T fields -e http.host -e http.request.uri -l | tr -d ‘\t‘
下面介紹參數含義:
-s 512 :只抓取前512個位元組資料
-i eth0 :捕獲eth0網卡
-n :禁止網路對象名稱解析
-f ‘tcp dst port 80‘ :只捕捉協議為tcp,目的連接埠為80的資料包
-R ‘http.host and http.request.uri‘ :過濾出http.host和http.request.uri
-T fields -e http.host -e http.request.uri :列印http.host和http.request.uri
-l :輸出到標準輸出
3、即時列印當前mysql查詢語句
tshark -s 512 -i eth0 -n -f ‘tcp dst port 3306‘ -R ‘mysql.query‘ -T fields -e mysql.query
下面介紹參數含義:
-s 512 :只抓取前512個位元組資料
-i eth0 :捕獲eth0網卡
-n :禁止網路對象名稱解析
-f ‘tcp dst port 3306‘ :只捕捉協議為tcp,目的連接埠為3306的資料包
-R ‘mysql.query‘ :過濾出mysql.query
-T fields -e mysql.query :列印mysql查詢語句
tshark使用-f來指定捕捉包過濾規則,規則與tcpdump一樣,可以通過命令man pcap-filter來查得。
tshark使用-R來過濾已捕捉到的包,與介面板wireshark的左上方Filter一致。
來自:https://www.centos.bz/2014/07/linux-commandline-capture-packets-tshark-wireshark/