歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Tcpreplay命令詳解

Tcpreplay命令詳解

日期:2017/2/28 14:36:58   编辑:Linux教程

工具的名稱就能猜到工具的作用,就是重放TCP的報文,但是這個工具究竟功能如何,是不是僅僅局限於在一個網卡上回放報文,這篇說明書主要介紹tcprelay的一些與測試有關的使用,在介紹tcpreplay命令的使用之前,先要介紹與之密切相關的一個命令:tcpprep,中文直譯就是tcp准備的意思,它的作用可以參見官方網站的介紹說明:

tcpprep is the pcap pre-processor for tcpreplay and tcprewrite. 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.


個人翻譯:(建議大家看man文件,閱讀3次就能夠比較好的理解了)


P:<list> - Must be one of the listed packets where the list corresponds to the packet number in the capture file.

Ex: -xP:1-5,9,15 would only send packets 1 through 5, 9 and 15.

根據參數後的參數值(報文編號)發送指定的報文。可以在ethereal中確認報文的編號,然後把需要的報文發送。可以用於排除ARP報文。

F:"<filter>" - BPF filter. See the tcpdump(8) man page for syntax.

未知,以後補充。

-X <match> Send all the packets except those specified

可選參數,就是-x參數的取反,參數內容也是一樣。

-v Verbose

可選參數,顯示trpprep生成cache文件的處理過程,就是一些信息的即時打印。

-V Version

顯示版本號。
Tcpprep使用小結

再構造cache文件的過程中我用的比較多的選項參數就-v、-P、-xB、-xP,一般都是client和server的模式,其它兩種模式沒有實驗過,暫時還不知道怎麼使用,bridge模式我使用過一次,結果發現報文是從一個網卡送出。

對於tcp和udp協議都做了測試,是可以支持的,icmp還沒有成功。對於網絡上的BT報文,只要你有pcap文件,也是可以構造cache文件來模擬完全真實的BT流量。

目前的使用就是這麼多,感覺還是很有用的,tcpreplay的參數有一部分是和tcpprep重復,下面的幫助文件說明就不詳細說明了,但是特殊有好用的參數會使用藍色字體標記出來給予重視。存在的不足是還沒有學會在nat模式下重放報文,現在所有的報文重放都是在透明模式下完成的。
Tcpreplay幫助文件說明

Usage: tcpreplay [args] <file(s)>

-A "<args>" Pass arguments to tcpdump decoder (use w/ -v)

可選參數,在使用tcpdump風格打印輸出信息時,同時再調用tcpdump中的參數,默認已經帶有“-n,-l”,所以一般看到的都是ip地址,而沒有主機名的打印,注意這個是在tcpreplay使用了-v參數時,才能使用,不帶-v不會報錯,但是沒有實際意義。格式:-vA “nnt”表示以tcpdump風格輸出報文信息,並且不打印時間戳、主機名、端口服務名稱。注意不要使用-c參數來指定打印的數據報文的個數,這樣發送出去的報文也會變少。

-b Bridge two broadcast domains in sniffer mode

可選參數,沒有用過

-c <cachefile> Split traffic via cache file

雙網卡回放報文必選參數,後面緊跟cache文件名,該文件為tcpprep根據對應的pcap文件構造出來。

-C <CIDR1,CIDR2,...> Split traffic by matching src IP

可選參數,

-D Data dump mode (set this BEFORE -w and -W)

可選參數,把應用層的數據,使用dump mode寫入到指定文件中去,和-w、-W參數一起使用。

-e <ip1:ip2> Specify IP endpoint rewriting

可選參數,指定端點的ip,即把發送報文的和接收的報文的ip都修改稱對應的參數值中指定的ip,但是這樣發送的出的報文不會區分client和server,還沒有發現使用的地方。

-f <configfile> Specify configuration file

可選參數,指定配置文件,目前不會使用。

-F Fix IP, TCP, UDP and ICMP checksums

可選參數,在發送報文時,自動糾正錯誤的校驗和。對測試DUT的校驗和檢驗還是有用的。

-h Help

顯示幫助文件。

-i <nic> Primary interface to send traffic out of

雙網卡回放報文必選參數,指定主接口。

-I <mac> Rewrite dest MAC on primary interface

可選參數,重寫主網卡發送出報文的目的MAC地址。

-j <nic> Secondary interface to send traffic out of

雙網卡回放報文必選參數,指定從接口。

-J <mac> Rewrite dest MAC on secondary interface

可選參數,重寫從網卡發送出報文的目的MAC地址。

-k <mac> Rewrite source MAC on primary interface

可選參數,重寫主網卡發送報文的源MAC地址。

-K <mac> Rewrite source MAC on secondary interface

可選參數,重寫從網卡發送報文的源MAC地址。

-l <loop> Specify number of times to loop

可選參數,指定循環的次數,測試過程發現不是那麼好用,有待確認。

-L <limit> Specify the maximum number of packets to send

可選參數,指定最大的發包數量。可以在確認連接的調試時使用。

-m <multiple> Set replay speed to given multiple

可選參數,指定一個倍數值,就是必默認發送速率要快多少倍的速率發送報文。加大發送的速率後,對於DUT可能意味著有更多的並發連接和連接數,特別是對於BT報文的重放,因為連接的超時是固定的,如果速率增大的話,留在session表中的連接數量增大,還可以通過修改連接的超時時間來達到該目的。

-M Disable sending martian IP packets

可選參數,表示不發送“火星”的ip報文,man文件中的定義是0/8、172/8、255/8。

-n Not nosy mode (not promisc in sniff/bridge mode)

可選參數,在使用-S參數,不對混雜模式進行偵聽。沒有測試過。

-N <CIDR1:CIDR2,...> Rewrite IP's via pseudo-NAT

可選參數,通過偽造的NAT,重寫IP地址。這個參數應該有很重要的應用,目前沒有測試使用。

-O One output mode

可選參數,沒有測試使用

-p <packetrate> Set replay speed to given rate (packets/sec)

Tcpreplay 的詳細介紹:請點這裡
Tcpreplay 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved