CentOS命令列抓包及包解析最新工具tshar

來源:互聯網
上載者:User

CentOS命令列抓包及包解析最新工具tshar

在centos下,當我們需要抓取網路資料包分析時,通常是使用tcpdump抓取網路raw資料包存到一個檔案,然後下載到本地使用wireshark介面網路分析工具進行網路包分析。
最近才發現,原來wireshark也提供有Linux命令列工具-tshark。tshark不僅有抓包的功能,還帶瞭解析各種協議的能力。下面我們以兩個執行個體來介紹tshark工具。

1、安裝方法
  1. CentOS: yum install -y wireshark
2、即時列印當前http請求的url(包括網域名稱)
  1. 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查詢語句
  1. 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/》

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.