capinfos, editcap, mergecap, dumpcap, text2pcap, reordercap (part 2 of 2)
dumpcap is Wireshark's capture engine: it only writes packets to a file and does not decode them, so it needs very little CPU and RAM and suits long captures. text2pcap turns a text hex dump back into a capture file (and can add dummy headers), and reordercap sorts packets by timestamp. Lab: capture box 192.168.147.10, peer 192.168.147.20, Wireshark 4.2.4 tools.
127.1 Why is it used?
- Long or unattended captures on busy servers: no decoding, low overhead.
- Ring buffers and autostop keep the disk from filling up.
- Wireshark and tshark themselves run dumpcap for live capture.
- text2pcap rebuilds a pcap from a hex dump in a log, a router 'show' output or a bug report.
- reordercap fixes out-of-order files after merges or multi-interface captures.
127.2 How it works
- Step 1
1.dumpcap runs on eth0 of 192.168.147.10 with capture filter icmp
- Step 2
2.Capture box pings the peer; the request passes the switch
- Step 3
3.dumpcap writes a copy of the request into the file
- Step 4
4.Peer's reply comes back and is written too
- Step 5
5.-c 5 reached: dumpcap stops and prints 'Packets captured: 5'
No dissection happens, so CPU and RAM use stay tiny
127.3 Interfaces and listing
- -D lists interfaces with numbers; -M makes it machine-readable (with the IP).
- -L lists link types (EN10MB = Ethernet); --list-time-stamp-types shows timestamp sources.
- -i can repeat, read stdin (-i -), a FIFO, a Windows pipe, TCP@host:port or rpcap://.
- --ifname / --ifdescr store a name and description in the pcapng; -S prints stats every second.
dumpcap -Ddumpcap -D -Mdumpcap -i eth0 -Ldumpcap -i eth0 --list-time-stamp-types$ dumpcap -D1. eth02. any3. lo (Loopback)4. nflog5. nfqueue$ dumpcap -D -M1. eth0 0 192.168.147.10 network2. any 0 network3. lo Loopback 0 127.0.0.1,::1 loopback$ dumpcap -i eth0 -LData link types of interface eth0 (use option -y to set): EN10MB (Ethernet) DOCSIS (DOCSIS)$ dumpcap -i eth0 --list-time-stamp-typesTimestamp types of the interface (use option --time-stamp-type to set): host (Host)127.4 Capture control
- -f sets the BPF capture filter; -d prints its compiled code and exits.
- -c 5 stops after 5 packets; -q hides the running count.
- -s 64 keeps only 64 bytes per packet, so tcpdump shows TCP options cut off ([|tcp]).
- -B (MiB) increases the buffer when packets drop; -p no promiscuous; -I Wi-Fi monitor mode.
dumpcap -i eth0 -f icmp -c 5 -w /tmp/c5.pcapngdumpcap -i eth0 -f icmp -c 5 -q -w /tmp/q5.pcapngdumpcap -i eth0 -s 64 -f 'tcp port 80' \ -c 6 -w /tmp/s64.pcapngcapinfos -l /tmp/s64.pcapngtcpdump -r /tmp/s64.pcapng -nn -c 1$ dumpcap -i eth0 -f icmp -c 5 -w /tmp/c5.pcapngCapturing on 'eth0'File: /tmp/c5.pcapngPackets: 1 Packets: 3 Packets: 5 Packets captured: 5Packets received/dropped on interface 'eth0': 5/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (100.0%)$ dumpcap -i eth0 -f icmp -c 5 -q -w /tmp/q5.pcapngCapturing on 'eth0'File: /tmp/q5.pcapngPackets captured: 5Packets received/dropped on interface 'eth0': 5/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (100.0%)$ capinfos -l /tmp/s64.pcapngPacket size limit: inferred: 64 bytes$ tcpdump -r /tmp/s64.pcapng -nn -c 103:08:43.145795 IP 192.168.147.10.38312 > 192.168.147.20.80: Flags [S], seq 1343362189, win 64240, options [mss 1460,sackOK,TS [|tcp]>127.5 802.11 channel: -k
- -k freq[,type[,center1[,center2]]] tunes a Wi-Fi card: 2437 = channel 6; HT20, HT40+/-, HT80, VHT160, VHT80+80.
- Works only on 802.11 cards: the lab's eth0 is type 1 (Ethernet) with no phy80211 folder.
- Real errors: -k cannot be combined with -D, and needs exactly one interface.
- Real use: sudo dumpcap -i wlan0 -I -k 2437 -w w.pcapng
cat /sys/class/net/eth0/typels /sys/class/net/eth0/phy80211dumpcap -D -k 2437dumpcap -i eth0 -i lo -k 2437,HT20$ cat /sys/class/net/eth0/type1$ ls /sys/class/net/eth0/phy80211ls: /sys/class/net/eth0/phy80211: No such file or directory$ dumpcap -D -k 2437dumpcap: Only one of -D, -L, -d, -k or -S may be supplied.$ dumpcap -i eth0 -i lo -k 2437,HT20dumpcap: Need one interface127.6 Output file and format
- -w names the file; -n pcapng (default), -P classic pcap.
- -w - streams raw data to stdout: sudo dumpcap -i eth0 -w - | tshark -r -
- --capture-comment stores a note; -g group-read; --temp-dir sets the temp folder.
dumpcap -i eth0 -f icmp -c 2 -n -w /tmp/ng.pcapngfile /tmp/ng.pcapngdumpcap -i eth0 -f icmp -c 2 -P -w /tmp/old.pcapfile /tmp/old.pcapdumpcap -i eth0 -f icmp -c 2 \ --capture-comment 'n127 lab test' -w /tmp/cm.pcapngcapinfos -k /tmp/cm.pcapng$ file /tmp/ng.pcapng/tmp/ng.pcapng: pcapng capture file - version 1.0$ file /tmp/old.pcap/tmp/old.pcap: pcap capture file, microsecond ts (little-endian) - version 2.4 (Ethernet, capture length 262144)$ capinfos -k /tmp/cm.pcapngCapture comment: n127 lab test127.7 Autostop and ring buffer
- -a duration:3 / filesize:50 (kB) / packets:4 / files:N stop the capture by itself.
- filesize stops once the file crosses the limit, so the file was 67364 bytes for a 50 kB limit.
- -b filesize:100 -b files:3: new file every 100 kB, keep only the last 3 (ring_00001 deleted).
- -b duration:300, -b interval:3600 (on the clock), -b packets:N; -b printname:stdout prints each closed file.
dumpcap -i eth0 -f icmp -a duration:3 -w /tmp/d3.pcapngcapinfos -c -u /tmp/d3.pcapngdumpcap -i eth0 -f 'tcp port 80' \ -a filesize:50 -w /tmp/f50.pcapng &curl -s -o /dev/null http://192.168.147.20/big.binls -l /tmp/f50.pcapngdumpcap -i eth0 -f icmp -a packets:4 -w /tmp/p4.pcapng$ capinfos -c -u /tmp/d3.pcapngNumber of packets: 29Capture duration: 2.876834529 secondsFile: /tmp/f50.pcapngPackets: 1 Packets: 15 Packets captured: 15$ ls -l /tmp/f50.pcapng-rw------- 1 root root 67364 Nov 9 03:09 /tmp/f50.pcapngFile: /tmp/p4.pcapngPackets: 1 Packets: 2 Packets: 4 Packets captured: 4- Step 1
1.Peer sends a big file; packets reach the capture box
- Step 2
2.dumpcap writes ring_00001 until it reaches 100 kB
- Step 3
3.Then ring_00002, then ring_00003
- Step 4
4.ring_00004 opens: the oldest file ring_00001 is deleted
- Step 5
5.Disk never fills up; the latest data is always kept
cd /tmp/ringdumpcap -i eth0 -f 'tcp port 80' \ -b filesize:100 -b files:3 -w ring.pcapngls -l /tmp/ringcd /tmp/bpdumpcap -i eth0 -f icmp -b packets:2 \ -b printname:stdout -a files:3 -w bp.pcapngPackets: 36 File: ./ring_00004_20261109030925.pcapngPackets: 44 Packets captured: 44$ ls -l /tmp/ring... 139404 Nov 9 03:09 ring_00002_20261109030925.pcapng... 132164 Nov 9 03:09 ring_00003_20261109030925.pcapng... 8252 Nov 9 03:09 ring_00004_20261109030925.pcapng./bp_00001_20261109030933.pcapng./bp_00002_20261109030934.pcapng./bp_00003_20261109030934.pcapng127.8 text2pcap: hex dump to pcap
- Default input: lines of an offset plus hex bytes (like od -Ax -tx1 output).
- -t '%H:%M:%S.%f' takes the time text before a packet as its timestamp; -o dec reads decimal offsets.
- -a ignores trailing ASCII, -D reads I/O direction, -r uses a regex with named groups (data, time, dir).
tail -c +41 /tmp/one.pcap > /tmp/frame.binod -Ax -tx1 -v /tmp/frame.bin > /tmp/frame.txthead -3 /tmp/frame.txttext2pcap /tmp/frame.txt /tmp/frame.pcapngtcpdump -r /tmp/frame.pcapng -nn(echo 10:15:30.250000; cat /tmp/frame.txt) > /tmp/ts.txttext2pcap -q -t '%H:%M:%S.%f' /tmp/ts.txt /tmp/ts.pcapngtcpdump -r /tmp/ts.pcapng -nn -tttt$ head -3 /tmp/frame.txt000000 66 d3 29 bf 8e e4 f2 10 47 4b 38 55 08 00 45 00000010 00 54 12 32 40 00 40 01 81 07 c0 a8 93 0a c0 a8000020 93 14 08 00 60 ee 4d 34 00 01 72 39 f1 6a 00 00$ text2pcap /tmp/frame.txt /tmp/frame.pcapngInput from: /tmp/frame.txtOutput to: /tmp/frame.pcapngOutput format: pcapngRead 1 potential packet, wrote 1 packet (432 bytes including overhead).$ tcpdump -r /tmp/frame.pcapng -nn03:09:43.000001 IP 192.168.147.10 > 192.168.147.20: ICMP echo request, id 19764, seq 1, length 64$ tcpdump -r /tmp/ts.pcapng -nn -tttt2026-11-09 10:15:30.250000 IP 192.168.147.10 > 192.168.147.20: ICMP echo request, id 19764, seq 1, length 64127.9 text2pcap: encapsulation and dummy headers
- -F pcap/pcapng chooses the format; -l 101 sets link type Raw IP (1 = Ethernet); -E sets encapsulation by name.
- -e 0x800 adds a dummy Ethernet header; its fake MACs spell SEND and RECV in ASCII.
- -i 1 adds a dummy IP header; -4 / -6 set the addresses (default 10.1.1.1 -> 10.2.2.2).
- -u 1000,69 adds UDP + IP (decoded as TFTP RRQ), -T 50000,80 adds TCP + IP (decoded as HTTP GET); -s/-S add SCTP.
text2pcap -q -F pcap /tmp/frame.txt /tmp/frame.pcaptail -c +55 /tmp/one.pcap > /tmp/ip.binod -Ax -tx1 -v /tmp/ip.bin > /tmp/ip.txttext2pcap -q -l 101 /tmp/ip.txt /tmp/raw.pcapngtcpdump -r /tmp/raw.pcapng -nntext2pcap -q -e 0x800 /tmp/ip.txt /tmp/e.pcapngtcpdump -r /tmp/e.pcapng -nn -e$ tcpdump -r /tmp/raw.pcapng -nnreading from file /tmp/raw.pcapng, link-type RAW (Raw IP), snapshot length 26214403:09:52.000001 IP 192.168.147.10 > 192.168.147.20: ICMP echo request, id 19764, seq 1, length 64$ tcpdump -r /tmp/e.pcapng -nn -e03:09:54.000001 20:53:45:4e:44:00 > 20:52:45:43:56:00, ethertype IPv4 (0x0800), length 98: 192.168.147.10 > 192.168.147.20: ICMP echo request, id 19764, seq 1, length 64printf '\000\001hello.txt\000octet\000' > /tmp/tftp.binod -Ax -tx1 -v /tmp/tftp.bin > /tmp/tftp.txttext2pcap -q -u 1000,69 /tmp/tftp.txt /tmp/u.pcapngtcpdump -r /tmp/u.pcapng -nnprintf 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n' > /tmp/http.binod -Ax -tx1 -v /tmp/http.bin > /tmp/http.txttext2pcap -q -T 50000,80 /tmp/http.txt /tmp/t.pcapngtcpdump -r /tmp/t.pcapng -nn$ tcpdump -r /tmp/u.pcapng -nn03:09:58.000001 IP 10.1.1.1.1000 > 10.2.2.2.69: TFTP, length 18, RRQ "hello.txt" octet$ tcpdump -r /tmp/t.pcapng -nn03:10:00.000001 IP 10.1.1.1.50000 > 10.2.2.2.80: Flags [none], seq 0:37, win 8192, length 37: HTTP: GET / HTTP/1.1127.10 reordercap: sort by timestamp
- mergecap -a appended part 2 before part 1, so capinfos showed strict time order False.
- reordercap sorted the packets: '6 frames, 1 out of order', time order True.
- -n skips writing when the input is already in order.
editcap -r /tmp/six.pcapng /tmp/first.pcapng 1-3editcap -r /tmp/six.pcapng /tmp/second.pcapng 4-6mergecap -a -w /tmp/mixed.pcapng \ /tmp/second.pcapng /tmp/first.pcapngcapinfos -o /tmp/mixed.pcapngreordercap /tmp/mixed.pcapng /tmp/sorted.pcapngcapinfos -o /tmp/sorted.pcapngreordercap -n /tmp/sorted.pcapng /tmp/again.pcapng$ capinfos -o /tmp/mixed.pcapngStrict time order: False$ reordercap /tmp/mixed.pcapng /tmp/sorted.pcapng6 frames, 1 out of order$ capinfos -o /tmp/sorted.pcapngStrict time order: True$ reordercap -n /tmp/sorted.pcapng /tmp/again.pcapng6 frames, 0 out of orderNot writing output file because input file is already in order.127.11 Help, version and diagnostics
- -h / -v in all three tools; all are Wireshark 4.2.4.
- --log-level, --log-fatal (abort even on a warning, useful in scripts), --log-domains, --log-file are the same in all three.
dumpcap -v | head -1text2pcap -v | head -1reordercap -v | head -1Dumpcap (Wireshark) 4.2.4 (Git commit c966d79150b6).Text2pcap (Wireshark) 4.2.4 (Git commit c966d79150b6).Reordercap (Wireshark) 4.2.4 (Git commit c966d79150b6).127.12 Comparison: dumpcap vs tcpdump vs tshark
| Point | dumpcap | tcpdump | tshark |
|---|---|---|---|
| Decodes packets | No | Short one-line decode | Full Wireshark dissectors |
| Default file format | pcapng | pcap | pcapng |
| CPU / RAM | Lowest | Low | Highest |
| Ring buffer keys | duration, interval, filesize, packets, files | -C, -G, -W | Same -b keys as dumpcap |
| Windows | Yes (with Npcap) | No built-in | Yes (with Npcap) |
127.13 Common mistakes
- Thinking capture needs the Wireshark GUI: both Wireshark and tshark run dumpcap internally.
- Running a GUI or tshark on a busy server: decoding eats CPU and RAM; capture with dumpcap and analyse later.
- Using -k on a non-Wi-Fi interface or with several interfaces.
- Open-ended captures without -a or -b.
127.14 Interview tips
- One-week capture with 1 GB free: -b filesize:100000 -b files:10 (only the latest 10 files stay).
- Why dumpcap over tcpdump: pcapng by default (many interfaces + comments), ring by duration/filesize/clock interval, same on Windows with Npcap.
- text2pcap turns a hex dump into a pcap and can add dummy Ethernet/IP/UDP/TCP headers.
- reordercap fixes 'Strict time order: False' files.