華為云計算 云知識 Wireshark是什么
Wireshark是什么

簡介

Wireshark是開源的非常流行的網(wǎng)絡(luò)封包分析軟件,功能十分強(qiáng)大,可以截取各種網(wǎng)絡(luò)封包,顯示網(wǎng)絡(luò)封包的詳細(xì)信息。

開源地址:https://github.com/wireshark/wireshark

編譯和測試方式

1.選擇操作環(huán)境

本文選用華為鯤鵬云服務(wù)ECS KC1實(shí)例做測試

2. 獲取源代碼

https://github.com/wireshark/wireshark/releases提供Wireshark各版本的源碼壓縮包,可以直接下載。

3. 編譯源代碼

本文以“wireshark-2.6.8”版本為例,下載源碼,并編譯安裝。

1)配置“wireshark-2.6.8”的依賴環(huán)境。

yum install autoconf automake libtool byacc flex libgcrypt-devel gcc-c++ gtk3 gtk3-devel libpcap-devel -y

2)下載“wireshark-2.6.8”源碼,并解壓。

cd /usr/local/src/
wget https://github.com/wireshark/wireshark/archive/v2.6.8.tar.gz
tar -xvf v2.6.8.tar.gz

3)編譯安裝Wireshark。

cd /usr/local/src/wireshark-2.6.8/
./autogen.sh
./configure with_qt=no with_gtk=yes --prefix=/usr/local/src/wireshark/
make -j4 && make install

4)配置Wireshark環(huán)境變量。

vi /etc/profile

將下面的環(huán)境變量配置插入倒數(shù)第三行,并保存退出。

export PATH=$PATH:/usr/local/src/wireshark/bin
done
export PATH=$PATH:/usr/local/src/wireshark/bin
unset i
unset -f pathmunge

5) 使環(huán)境變量生效。

source /etc/profile

4. 測試已完成編譯的軟件

1)查看Wireshark版本號。

tshark --version

回顯內(nèi)容如下:

Running as user "root" and group "root". This could be dangerous.
TShark (Wireshark) 2.6.8 (Git Rev Unknown from unknown)

2)使用Wireshark抓取eth0網(wǎng)卡數(shù)據(jù)。

a.抓取數(shù)據(jù)。

tshark -w package.txt -i eth0 -q

回顯內(nèi)容如下:

Running as user "root" and group "root". This could be dangerous.
Capturing on 'eth0'

b.查看抓取的數(shù)據(jù)。

使用“Ctrl”+“Z”按鍵停止抓取,采用tshark打開“package.tx”t查看。

tshark -r package.txt -x -V | more

tshark參數(shù)說明

   “-w”設(shè)置數(shù)據(jù)保存成的文件名稱。

   “-i”設(shè)置抓包的網(wǎng)絡(luò)接口。

   “-r”設(shè)置tshark分析的輸入文件。

   “-x”設(shè)置在解碼輸出結(jié)果中,以“HEX dump”的方式顯示具體數(shù)據(jù)。

   “-V”設(shè)置解碼結(jié)果的細(xì)節(jié)輸出格式。

回顯內(nèi)容如下:

Running as user "root" and group "root". This could be dangerous.
Frame 1: 72 bytes on wire (576 bits), 72 bytes captured (576 bits) on interface 0
   Interface id: 0 (eth0)
       Interface name: eth0
   Encapsulation type: Ethernet (1)
   Arrival Time: Jul  8, 2019 20:20:22.552687479 CST
   [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1562588422.552687479 seconds

其他安裝方式

對于CentOS,可以直接使用yum安裝。

yum install wireshark wireshark-devel -y

安裝完成后,其他的操作類似,但是yum安裝的版本是“wireshark 1.10.14”。