一、场景
由于测试过程想对生产环境的数据进行录制。并回放给测试服务,所以进行尝试
二、工具
tcpreplay
三、录制数据包
sudo tcpdump -i enp4s0 dst port 8000 -w http.pcap -v
四、tcpreplay-edit进行回放
sudo tcpreplay-edit --unique-ip -l 1 -i enp4s0 ./http.pcap
$ sudo tcpreplay-edit --unique-ip -l 1 -i enp4s0 ./http.pcap
Actual: 10 packets (1124 bytes) sent in 2.09 seconds
Rated: 536.9 Bps, 0.004 Mbps, 4.77 pps
Flows: 3 flows, 1.43 fps, 10 flow packets, 0 non-flow
Statistics for network device: enp4s0
Successful packets: 10
Failed packets: 0
Truncated packets: 0
Retried packets (ENOBUFS): 0
Retried packets (EAGAIN): 0
五、使用tcpliveplay回放
$ sudo tcpliveplay enp4s0 ./http.pcap 192.168.3.52 38:ad:be:97:69:23 8000
new source port:: 8000
Random Local SEQ: 621619904
Packets Scheduled 8
Sending Local Packet............... [1]
Sending Local Packet............... [2]
Sending Local Packet............... [3]
Sending Local Packet............... [4]
Sending Local Packet............... [5]
Sending Local Packet............... [6]
Sending Local Packet............... [7]
Sending Local Packet............... [8]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ CONGRATS!!! You have successfully Replayed your pcap file './http.pcap'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----------------TCP Live Play Summary----------------
- Packets Scheduled to be Sent & Received: 8
- Actual Packets Sent & Received: 8
- Total Local Packet Re-Transmissions due to packet
- loss and/or differing payload size than expected: 7
- Thank you for Playing, Play again!
----------------------------------------------------------
六、讨论
1、数据包无法响应,服务端不能正产进行交互
参考链接:
https://blog.csdn.net/xingqingly/article/details/104373975/
https://blog.csdn.net/leeezp/article/details/125448834
tcpreplay + tcpdump 联合起来进行回放和监控_tcpreplay回放数据包 服务端没数据-CSDN博客
标签:Sending,回放,packets,Packet,...............,录包,tcpreplay,Local From: https://www.cnblogs.com/fireblackman/p/18316202