tcpdump能夠轉(zhuǎn)儲(chǔ)網(wǎng)絡(luò)上的數(shù)據(jù)流。
命令

選項(xiàng)

關(guān)于expression表達(dá)式
用來選擇要轉(zhuǎn)儲(chǔ)的數(shù)據(jù)報(bào),如果沒有指定expression,就轉(zhuǎn)儲(chǔ)全部的報(bào)文。否則轉(zhuǎn)儲(chǔ)相對(duì)expression為true的數(shù)據(jù)報(bào)。修飾子由三種不同的類型
a) type 指出標(biāo)識(shí)名稱或者標(biāo)識(shí)數(shù)字代表什么類型的東西??梢允褂妙愋陀衕ost ,net和port 例如’host? foo’, ‘net 128.3’,’port? 20’。 如果不指定類型修飾子 ,就使用缺省的host 。
b) dir 方向修飾子,指出相對(duì)于標(biāo)識(shí)的傳輸方向(數(shù)據(jù)是傳入還是傳出 標(biāo)識(shí))可以使用的方向有src ,dst,src or dst 和src and dst 。例如,’src? foo’? ‘dst? net? 128.3’? ‘src? or? dst? port? ftp-data’ 。如果不指定方向修飾子,就使用缺省的src or dst 。
c) proto 協(xié)議裝修子要求匹配指定的協(xié)議??梢允褂玫膮f(xié)議有:ether,fddi,ip,arp,rarp,decnet,lat,sca,moprc,mopdl,tcp和udp 。例如,’ether src foo’? ‘a(chǎn)rp? net? 128.3’? ‘tcp? port? 21’? 。如果不指定協(xié)議修飾子,就使用所有符合的協(xié)議。
d) 還有一些特殊的關(guān)鍵字:gateway,broadcaset,less,greater和數(shù)學(xué)表達(dá)式。例如,less? length 。(len<=length)
greater? length . ip broadcaset? ? ip? multicast? 。
e) 操作符 。取反操作 (‘!’ or? ‘not’)? 連接操作(‘&&’ or ‘a(chǎn)nd’) 或操作(‘||’ or ‘or’)
實(shí)例
1) 在指定網(wǎng)絡(luò)接口抓取10個(gè)網(wǎng)絡(luò)數(shù)據(jù)包
tcpdump? -i? eth0? ? -c? 10
2) 在指定接口抓取與該主機(jī)通信的所有數(shù)據(jù)包
tcpdump? -i? eth0? ? host? hostname
3) 在指定接口抓取端口21上的數(shù)據(jù)包
tcpdump? -i? eth0? ? port? 21
4) 在指定端口抓取tcp并且目標(biāo)端口為80的數(shù)據(jù)包
tcpdump? -i? eth0? ? tcp? and? dst? port? 21
5) 獲取IP A和IP B之間的通信,使用命令注意轉(zhuǎn)義符號(hào)
tcpdump -i eth0? host 192.168.85.21 and \( 192.168.85.19\)?