Skip to content

Instantly share code, notes, and snippets.

@qbein
Created July 11, 2015 10:01
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save qbein/e936fc6afd524c901af4 to your computer and use it in GitHub Desktop.
Save qbein/e936fc6afd524c901af4 to your computer and use it in GitHub Desktop.
Replay pcap/pcapng TCP traffic using netcat
For development it may be useful to be able to replay TCP traffic (e.g. HTTP). The dump can be created using WireShark or tcpdump:
$ tcpdump -s 0 port http -i en0 -w dump.pcap
To generate data files that can be replayed through netcat we use tcptrace:
$ tcptrace -e input.pcapng
Finally replay the HTTP traffic using netcat to host 192.168.1.1 port 80
$ cat a2b_contents.dat | nc -v 192.168.1.1 80
If you need to replay the raw network traffic, we need to do some massaging using tcpprep and tcprewrite before using tcpreplay to replay the raw packages. Note that due to limitation of tcprewrite this will not replay any traffic to the network: http://tcpreplay.synfin.net/wiki/FAQ#Doestcpreplaysupportsendingtraffictoaserver.
$ tcpprep --port --cachefile=dump.cache --pcap=dump.pcapng
$ tcprewrite --portmap=80:8080 --endpoints=127.0.0.1:127.0.0.2 --cachefile=dump.cache --infile=dump.pcapng --outfile=transformed.pcapng
$ tcpreplay -i en0 transformed.pcapng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment