<wbr>工具的名稱就能猜到工具的作用,就是重放TCP的報文,但是這個工具究竟功能如何,是不是僅僅侷限於在一個網路卡上回放報文,這篇說明書主要介紹tcprelay的一些與測試有關的使用,在介紹tcpreplay命令的使用之前,先要介紹與之密切相關的一個命令:tcpprep,中文直譯就是tcp準備的意思,它的作用可以參見官方網站的介紹說明:<wbr><wbr><wbr>tcpprep is the pcap pre-processor for and . The purpose of tcpprep is to create a cache file which is used to "split" traffic into two sides (often called primary/secondary or client/server). If you are intending to use tcpreplay with two NIC's, then tcpprep is what decides which interface each packet will use. By using a seperate process to generate cache files, tcpreplay can send packets at a much higher rate then if it had to do the calculations to split traffic itself.
CET-4翻譯:(建議大家看man檔案,閱讀3次就能夠比較好的理解了)
<wbr><wbr><wbr>tcpprep是一個在tcpreplay和tcprewrite(3.0.beta11版本才有,這裡不討論)之前使用的pcap檔案的處理程式。使用tcpprep的目的就是建立一個cache檔案,用於分離通訊流量中的兩方(通常叫做主要的/次要的 或者客戶端/伺服器)。如果你正打算在兩塊網路卡上使用tcpreplay的話,那麼tcpprep就是用來決定每一個報文(packet)從哪一個介面發出。透過使用這樣一個分離的程式來建立一個cache檔案,tcpreplay就可以根據這個cache檔案透過自身的計算來分離流量,高速率的傳送報文。
<wbr><wbr><wbr>cache檔案的作用解釋,主要是加速報文的傳送,cache檔案中存放著pcap檔案中每個幀的編號和時間戳等資訊,以達到tcpreplay回放時可以更加快速的傳送報文的目的。
<wbr><wbr><wbr>其實我們要使用tcpreplay的功能的話,肯定就是它的重放功能,而重放的話肯定是一個客戶端和伺服器的互動過程,例如ftp、tftp、sqlnet、rtsp、mms等應用層協議的互動過程,我們只要有正確和足夠的pcap檔案,只需要製作cache檔案,使用tcpreplay的命令,就不需要每次都搭建一個真實的測試環境來測試DUT對該協議的支援程度。所以在介紹tcpreplay之前先介紹tcpprep這個命令的使用。tcprewrite提供的功能暫時不做研究。
Tcpprep幫助檔案說明
<wbr><wbr><wbr>由於時間問題,這次不能對man檔案一一做解釋,這個說明文件主要是對-h列印出來的命令引數作一個說明,結合幾個實際的例子來說明tcpprep的使用。強烈建議大家去官方網站去閱讀他們提供的文件,,我這裡有列印的內容,有興趣的可以拿去看一下。
<wbr><wbr><wbr>Usage: tcpprep [-a -n -N | -c | -p | -r ]
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>-o -i
-a Split traffic in Auto Mode
一般情況下都需要該引數,表示按模式自動分離的通訊流量生成cache檔案,這個引數一半都和-n引數一起使用,表示自動分離採取的拓撲模式,來決定採取那種模式分離通訊流量的雙方。
-c CIDR1,CIDR2,... <wbr><wbr><wbr><wbr><wbr>Split traffic in CIDR Mode
可選引數,表示分離流量時採用CIDR(無類別域間路由選擇)模式。格式:tcpprep <wbr>-ac 10.10.0.0/24,表示把源地址匹配10.10.0.0/24網段的報文全部由主網路卡傳送,剩下的報文由從網路卡傳送出來,這裡還有一點需要補充,就是tcpreplay在重放報文時對兩個網路卡的定義很明確,一個主網路卡(primary interface),一個是從網路卡(secondary interface),不同的模式,兩塊網路卡的屬性不一樣。該引數不能和-r,-a一起使用。
-C <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Embed comment in tcpprep cache file
可選引數,表示在cache檔案中嵌入註釋內容,可以用於註釋說明cache檔案的內容,注意使用時引數位置,不要放在最後,我測試時放在-o引數值的後面就報錯,放到-i引數之前就可以。生成cache檔案後使用-P可以檢視寫入的內容。
-h <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Help
顯示幫助檔案。
-i <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Input capture file to process
生成cache檔案的必帶引數,後面緊跟pcap檔名,表示這個pcap檔案需要處理。
-m <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Minimum mask length in Auto/Router mode
可選引數,在選用router模式時使用,表示最小掩碼,預設是30(2個有效ip地址)。
-M <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Maximum mask length in Auto/Router mode
可選引數,在選用router模式時使用,表示最大掩碼,預設是8(1600萬個ip地址)。
-n <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Use specified algorithm in Auto Mode
生成cache檔案的必帶引數,後面緊跟模式名稱,可選項有(bridge|router|client|server),目前2.3.5版本只支援這4種模式。模式的選擇很關鍵,例如在客戶端使用ftp軟體下載檔案,那麼你在客戶端抓到的報文生成的pcap檔案,那麼就選用client模式,在伺服器端抓到的報文生成的pcap檔案就選用server模式。只有模式選對了,才能正確的分離流量從正確的介面發出正確的報文。注意:Server端的報文由主網路卡傳送出去,Client端的報文由從網路卡傳送出去。怎麼確定主從網路卡由tcpreplay的命令(-i –j兩個引數)來決定。
-N client|server <wbr><wbr><wbr><wbr><wbr><wbr><wbr>Classify non-IP traffic as client/server
可選引數,表示非IP的流量(例如ARP報文)從哪個介面送出,因為很多的tcpprcp支援的模式中,都依賴於IP頭部中的IP地址資訊來決定報文是從client端還是從server端傳送出去。但是並不是所有的報文都是IPv4結構的,所以這種情況下,tcpprep不能確定這些非IPv4型別的報文應該從哪個介面傳送出去,所以,預設的配置就是從client的介面傳送出去。如果你硬要正確的分離出非IPv4報文的話,可以使用MAC address模式(--mac)。3.0版本才支援。
-o <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Output cache file name
生成cache檔案的必帶引數,後面緊跟cache檔名,表示這個輸出的cache檔案以這個名字命名。
-p <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Split traffic based on destination port
<wbr><wbr><wbr>可選引數,基於目的埠來分離通訊流量,它區分的依據是認為0-1023埠都是伺服器的端發出的報文,其它的埠都是客戶端發出的報文,具體的埠對應的/etc/services檔案裡的的內容。使用的格式:-p /etc/services,可以根據自己的需要來製作一個檔案也可以。
-P <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Print comment in tcpprep file
<wbr><wbr><wbr>可選引數,檢視cache檔案的內容。
-r <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Split traffic in Regex Mode
<wbr><wbr><wbr>可選引數,表示使用Regex模式分離通訊流量,有點類似於CIDR模式,但是它匹配的是伺服器的源IP。man檔案提示不能和-a、-c引數一起使用,但是我使用了也沒有報錯,格式:-r "(192)"或-r "(192|172).....*",具體應用還有待實驗。
-R <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Specify a ratio to use in Auto Mode
<wbr><wbr><wbr>可選引數,一個比例值,這個比例值的意義是伺服器端發起的連線數和客戶端發起的連線數的比例,這個值大於2的話就視為server端。這個英文原意我也不是太肯定,大家可以參考一下原文:
The ratio of server connections to client connections <wbr>necessary to <wbr>be classified as a server in auto mode. <wbr>A system is classified as a server if [# server connections] >= ([# client connections] * [ratio]). <wbr>Default is: 2.0
-s <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Specify service ports in /etc/services format
<wbr><wbr><wbr>可選引數,在man檔案中沒有對該引數的解釋,估計就是按/etc/services檔案裡的格式來定義服務的埠,沒有太多的研究意義。
-x <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Only send the packets specified
<wbr><wbr><wbr>重要的可選引數,表示按照引數定義的需求來定義傳送報文。後面還有具體的引數,因為在我們的抓包過程中,可能會由於網路環境原因,抓到了許多我們不需要回放的報文,我們就可以根據這個引數決定我們需要回放哪些報文內容。具體的引數意思如下:
<wbr><wbr><wbr>
<wbr><wbr><wbr>在CIDR模式下必須匹配源IP,格式:-xS:100.1.1.0/24,10.10.10.0/26。多個用逗號隔開,引數個數沒有試過,3個沒有問題。
D:,... - Dst IP must match specified CIDR(s)
在CIDR模式下必須匹配目的IP,格式同上。
B:,... - Both src and dst addresses must match
必須同時匹配源和目的IP,格式同上。
E:,... - Either src or dst address must match
匹配源或目的IP,格式同上。
P: <wbr>- Must be one of the listed packets where the list corresponds <wbr>to <wbr>the <wbr>packet number in the capture file. <wbr>
Ex: -xP:1-5,9,15 would only send packets 1 through 5, 9 and 15.
根據引數後的引數值(報文編號)傳送指定的報文。可以在ethereal中確認報文的編號,然後把需要的報文傳送。可以用於排除ARP報文。
F:"" <wbr>- BPF filter. <wbr>See the <wbr>tcpdump(8) <wbr>man <wbr>page <wbr>for syntax.
未知,以後補充。
-X <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Send all the packets except those specified
<wbr><wbr><wbr>可選引數,就是-x引數的取反,引數內容也是一樣。
-v <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Verbose
<wbr><wbr><wbr>可選引數,顯示trpprep生成cache檔案的處理過程,就是一些資訊的即時列印。
-V <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Version
<wbr><wbr><wbr>顯示版本號。
Tcpprep使用小結
<wbr><wbr><wbr>再構造cache檔案的過程中我用的比較多的選項引數就-v、-P、-xB、-xP,一般都是client和server的模式,其它兩種模式沒有實驗過,暫時還不知道怎麼使用,bridge模式我使用過一次,結果發現報文是從一個網路卡送出。
<wbr><wbr><wbr>對於tcp和udp協議都做了測試,是可以支援的,icmp還沒有成功。對於網路上的BT報文,只要你有pcap檔案,也是可以構造cache檔案來模擬完全真實的BT流量。
<wbr><wbr><wbr>目前的使用就是這麼多,感覺還是很有用的,tcpreplay的引數有一部分是和tcpprep重複,下面的幫助檔案說明就不詳細說明了,但是特殊有好用的引數會使用藍色字型標記出來給予重視。存在的不足是還沒有學會在nat模式下重放報文,現在所有的報文重放都是在透明模式下完成的。
<wbr>
<wbr>
Tcpreplay幫助檔案說明
<wbr><wbr><wbr>Usage: tcpreplay [args]
-A "" <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Pass arguments to tcpdump decoder (use w/ -v)
<wbr><wbr><wbr>可選引數,在使用tcpdump風格列印輸出資訊時,同時再呼叫tcpdump中的引數,預設已經帶有“-n,-l”,所以一般看到的都是ip地址,而沒有主機名的列印,注意這個是在tcpreplay使用了-v引數時,才能使用,不帶-v不會報錯,但是沒有實際意義。格式:-vA “nnt”表示以tcpdump風格輸出報文資訊,並且不列印時間戳、主機名、埠服務名稱。注意不要使用-c引數來指定列印的資料包文的個數,這樣傳送出去的報文也會變少。
-b <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Bridge two broadcast domains in sniffer mode
<wbr><wbr><wbr>可選引數,沒有用過
-c <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Split traffic via cache file
<wbr><wbr><wbr>,後面緊跟cache檔名,該檔案為tcpprep根據對應的pcap檔案構造出來。
-C <wbr><wbr><wbr>Split traffic by matching src IP
<wbr><wbr><wbr>可選引數,
-D <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Data dump mode (set this BEFORE -w and -W)
可選引數,把應用層的資料,使用dump mode寫入到指定檔案中去,和-w、-W引數一起使用。
-e <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Specify IP endpoint rewriting
<wbr><wbr><wbr>可選引數,指定端點的ip,即把傳送報文的和接收的報文的ip都修改稱對應的引數值中指定的ip,但是這樣傳送的出的報文不會區分client和server,還沒有發現使用的地方。
-f <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Specify configuration file
<wbr><wbr><wbr>可選引數,指定配置檔案,目前不會使用。
-F <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Fix IP, TCP, UDP and ICMP checksums
<wbr><wbr><wbr>可選引數,在傳送報文時,自動糾正錯誤的校驗和。對測試DUT的校驗和檢驗還是有用的。
-h <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Help
<wbr><wbr><wbr>顯示幫助檔案。
-i <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Primary interface to send traffic out of
<wbr><wbr><wbr>雙網路卡回放報文必選引數,指定主介面。
-I <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Rewrite dest MAC on primary interface
<wbr><wbr><wbr>可選引數,重寫主網路卡傳送出報文的目的MAC地址。
-j <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Secondary interface to send traffic out of
<wbr><wbr><wbr>雙網路卡回放報文必選引數,指定從介面。
-J <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Rewrite dest MAC on secondary interface
<wbr><wbr><wbr>可選引數,重寫從網路卡傳送出報文的目的MAC地址。
-k <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Rewrite source MAC on primary interface
<wbr><wbr><wbr>可選引數,重寫主網路卡傳送報文的源MAC地址。
-K <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Rewrite source MAC on secondary interface
<wbr><wbr><wbr>可選引數,重寫從網路卡傳送報文的源MAC地址。
-l <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Specify number of times to loop
<wbr><wbr><wbr>可選引數,指定迴圈的次數,測試過程發現不是那麼好用,有待確認。
-L <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Specify the maximum number of packets to send
<wbr><wbr><wbr>可選引數,指定最大的發包數量。可以在確認連線的除錯時使用。
-m <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Set replay speed to given multiple
<wbr><wbr><wbr>可選引數,指定一個倍數值,就是必預設傳送速率要快多少倍的速率傳送報文。加大傳送的速率後,對於DUT可能意味著有更多的併發連線和連線數,特別是對於BT報文的重放,因為連線的超時是固定的,如果速率增大的話,留在session表中的連線數量增大,還可以透過修改連線的超時時間來達到該目的。
-M <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Disable sending martian IP packets
<wbr><wbr><wbr>可選引數,表示不傳送“火星”的ip報文,man檔案中的定義是0/8、172/8、255/8。
-n <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Not nosy mode (not promisc in sniff/bridge mode)
<wbr><wbr><wbr>可選引數,在使用-S引數,不對混雜模式進行偵聽。沒有測試過。
-N <wbr><wbr><wbr>Rewrite IP's via pseudo-NAT
<wbr><wbr><wbr>可選引數,透過偽造的NAT,重寫IP地址。這個引數應該有很重要的應用,目前沒有測試使用。
-O <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>One output mode
<wbr><wbr><wbr>可選引數,沒有測試使用
-p <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Set replay speed to given rate (packets/sec)
<wbr><wbr><wbr>可選引數,指定每秒傳送報文的個數,指定該引數,其它速率相關的引數被忽略,最後的列印資訊不會有速率和每秒傳送報文的統計。
-P <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Print PID
<wbr><wbr><wbr>可選引數,表示在輸出資訊中列印PID的資訊,用於單使用者或單帳戶模式下暫停和重啟程式。
-r <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Set replay speed to given rate (Mbps)
<wbr><wbr><wbr>可選引數,指定傳送的速率。目前-m/-r/-p這3個引數的相互關係還需要確認。
-R <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Set replay speed to as fast as possible
<wbr><wbr><wbr>可選引數,讓報文線速傳送。
-s <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Randomize src/dst IP addresses w/ given seed
<wbr><wbr><wbr>可選引數,
-S <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Sniff interface(s) and set the snaplen length
<wbr><wbr><wbr>可選引數,
-t <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Override MTU (defaults to 1500)
<wbr><wbr><wbr>可選引數,指定MTU,標準的10/100M網路卡的預設值是1500。
-T <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Truncate packets > MTU so they can be sent
<wbr><wbr><wbr>可選引數,截去報文中MTU大於標準值的部分再傳送出去,預設是不傳送,skip掉。目前還有疑問,為什麼會產生MTU大於1500位元組的包,在BT報文中,這種包比較常見。
-u pad|trunc <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Pad/Truncate packets which are larger than the snaplen
<wbr><wbr><wbr>可選引數,後面的引數值二選一,snaplen是指保留資料包的長度,這裡的trunc引數值和MTU沒有任何關係,不要混淆。
-v <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Verbose: print packet decodes for each packet sent
<wbr><wbr><wbr>可選引數,沒傳送一個報文都以tcpdump的風格列印出對應的資訊。
-V <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Version
<wbr><wbr><wbr>檢視版本號。
-w <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Write (primary) packets or data to file
<wbr><wbr><wbr>可選引數,將主網路卡傳送的報文寫入一個檔案中,引數後緊跟檔名。
-W <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Write secondary packets or data to file
<wbr><wbr><wbr>可選引數,將從網路卡傳送的報文寫入一個檔案中,引數後緊跟檔名。
-x <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Only send the packets specified
<wbr><wbr><wbr>可選引數,傳送匹配引數值的報文,這裡各個引數具體的含義和tcpprep中的一樣,
S:,... - Src IP must match specified CIDR(s)
<wbr><wbr><wbr>在CIDR模式下必須匹配源IP,格式:-xS:100.1.1.0/24,10.10.10.0/26。多個用逗號隔開,引數個數沒有試過,3個沒有問題。
D:,... - Dst IP must match specified CIDR(s)
在CIDR模式下必須匹配目的IP,格式同上。
B:,... - Both src and dst addresses must match
必須同時匹配源和目的IP,格式同上。
E:,... - Either src or dst address must match
匹配源或目的IP,格式同上。
P: <wbr>- Must be one of the listed packets where the list corresponds <wbr>to <wbr>the <wbr>packet number in the capture file. <wbr>
Ex: -xP:1-5,9,15 would only send packets 1 through 5, 9 and 15.
根據引數後的引數值(報文編號)傳送指定的報文。可以在ethereal中確認報文的編號,然後把需要的報文傳送。可以用於排除ARP報文。
F:"" <wbr>- BPF filter. <wbr>See the <wbr>tcpdump(8) <wbr>man <wbr>page <wbr>for syntax.
未知,以後補充。
-X <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Send all the packets except those specified
<wbr><wbr><wbr>可選引數,-x的引數內容取反。引數內容一樣。
-1 <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Send one packet per key press
<wbr><wbr><wbr>可選引數,引數內容就是阿拉伯數字1,這個引數對於確定連線的建立,相當好用,根據按Enter鍵傳送報文,可以將報文一個一個傳送,來判斷連線的狀態。也可以用於故障定位。
-2 <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Layer 2 data
<wbr><wbr><wbr>可選引數,在2層加入資料。
-4 <wbr><wbr><wbr>Rewrite port numbers
<wbr><wbr><wbr>可選引數,重寫埠號,對於測試特殊埠的應用比較實用。
... <wbr><wbr><wbr><wbr>File list to replay
<wbr><wbr><wbr>可選引數,沒有實驗過。
配置例項
1、 <wbr>重放在客戶端ftp連線的報文
a、 <wbr>在客戶端使用ethereal抓包,存為檔案
b、 <wbr>將操作,製作cache檔案。
[root@A ~]# tcpprep -an client -i ftp.pcap -o ftp.cache –v
c、 <wbr>將DUT裝置的兩個介面和PC的兩個介面使用網線連線,使用tcpreplay重放報文。注意防火牆的配置為網橋(透明)模式。
[root@A ~]# tcpreplay -c ftp.cache -i eth0 -j eth1 ftp.pcap <wbr>-R –v
-R參數列示全速傳送,-v顯示列印資訊。
2、 <wbr>重放在客戶端BT連線的報文
a、 <wbr>在實驗室BT下載一些臺灣的娛樂節目和熱門的大片,使用ethereal抓包,存為bt.pcap檔案。注意pcap檔案大小的控制,對pc的記憶體要求比較高,我儲存了一個600多M的pcap檔案用了40多分鐘,大家有需要可以直接從實驗室copy。
b、 <wbr>將bt.pcap檔案進行tcpprep操作,製作cache檔案。
[root@A ~]# tcpprep -an client -i bt.pcap -o bt.cache -C "100M BT Packet" –v
<wbr><wbr><wbr>製作cache檔案,在cache檔案中寫入“100M BT Packet”的註釋。
c、 <wbr>使用tcpreplay重放報文。
[root@A ~]# tcpreplay -c bt.cache -i eth0 -j eth1 bt.pcap -v –R
3、 <wbr>重放tftp伺服器上抓到的報文
a、 <wbr>在tftp伺服器上使用ethereal抓包,存為tftp.pcap檔案。
b、 <wbr>將pcap檔案進行tcpprep的操作,製作cache檔案。
[root@A ~]# tcpprep -an server -i tftp.pcap -o tftp.cache –v
注意:我在測試的時候犯了一個錯誤,使用DUT的tftp升級來做實驗,同時穿過DUT重放報文,結果在網路卡傳送報文的後,DUT的mac地址做了的回應,導致互動過程沒有穿過DUT,這個問題比較搞笑,上午弄了半天才發現原因,開始還以為udp的連線不能重放。
c、 <wbr>使用tcpreplay重放報文。
[root@A ~]# tcpreplay -c tftp.cache -i eth0 -j eth1 tftp.pcap –v
[@more@]tcpreplay -i eth1 -l 0 -M 100m --enable-file-cache #.pcap
tcpreplay -i eth1 -l 0 --enable-file-cache -t 1session_100.pcap
(1 cpu Mem 1G)
cpu MHz : 2400.114
MemTotal: 1028552 kB
tcpreplay -i eth0 -l 0 -t --enable-file-cache pcap
單個tcpreplay:
405Mbps/sec
雙個tcpreplay:
220Mbps/sec 280Mbps/sec
(2 cpu Mem 1G)
cpu MHz : 2992.649
MemTotal: 1027044 kB
tcpreplay -i eth4 -l 1000 -t fzgs2.pcap
單個tcpreplay:
613.52Mbps/sec
703.93Mbps/sec
704.01Mbps/sec
703.89Mbps/sec
雙個tcpreplay:
313.02Mbps/sec 327.12Mbps/sec
tcpreplay -i eth4 -l 1000 -t --enable-file-cache pcap
單個tcpreplay:
791.00Mbps/sec
624.74Mbps/sec
789.82Mbps/sec
794.15Mbps/sec
雙個tcpreplay:
422.18Mbps/sec 389.52Mbps/sec
424.28Mbps/sec 382.48Mbps/sec
346.46Mbps/sec 342.15Mbps/sec
三個tcpreplay:
286.58Mbps/sec 176.88Mbps/sec 190.77Mbps/sec