capinfos, editcap, mergecap, dumpcap, text2pcap, reordercap (1/2)
capinfos, editcap and mergecap work on saved capture files: capinfos reports what is inside, editcap writes a new file with packets removed or changed, and mergecap joins files into one timeline. They ship with Wireshark (Windows/macOS) or wireshark-common / wireshark-cli (Linux) and need no root. Lab: cli 192.168.146.10, web 192.168.146.20, tools version 4.2.4.
126.1 Why is it used?
- Check a capture before analysing it: packets, duration, start/end time, format.
- Cut a huge capture down to the incident window or split it into small parts.
- Convert pcapng to pcap for old tools, truncate payloads for privacy.
- Fix wrong clocks, remove duplicates and merge captures from several places.
126.2 How it works
- Step 1
1.cli 192.168.146.10 pings and curls web 192.168.146.20 via the Docker bridge
- Step 2
2.tcpdump on cli saves ping.pcap (10 packets) and curl.pcap (20 packets)
- Step 3
3.capinfos only reads a file and prints a report
- Step 4
4.editcap reads a file and writes a NEW file with packets removed/changed
- Step 5
5.mergecap merges ping + curl in timestamp order into all.pcapng (30 packets)
The input file is never modified; editcap and mergecap always write a new file
126.3 capinfos: individual infos
- No option = full report: file type, encapsulation, packets, data size, duration, bit rate, time order.
- Pick single infos: -c packets, -d data size, -u duration, -a / -e first / last packet time.
- -S shows times as epoch seconds, handy for editcap -A/-B.
tcpdump -i eth0 -nn -c 10 -w ping.pcap icmpcapinfos ping.pcapcapinfos -c -d -u -a -e ping.pcapcapinfos -c -a -e -S ping.pcap$ capinfos ping.pcapFile type: Wireshark/tcpdump/... - pcapFile encapsulation: EthernetNumber of packets: 10Data size: 980 bytesCapture duration: 4.054185 secondsData bit rate: 1933 bits/sStrict time order: True$ capinfos -c -d -u -a -e ping.pcapNumber of packets: 10Data size: 980 bytesCapture duration: 4.054185 secondsFirst packet time: 2026-11-09 03:02:35.005683Last packet time: 2026-11-09 03:02:39.059868$ capinfos -c -a -e -S ping.pcapNumber of packets: 10First packet time: 1794193355.005683Last packet time: 1794193359.059868126.4 capinfos: table and CSV reports
- -T makes a tab-separated table, one line per file; -r removes the header row.
- -m commas + -Q double quotes = CSV that opens in Excel.
- -M prints raw values without rounding (1933.80 bits/sec).
- -C stops at the first error; without it capinfos moves on to the next file.
capinfos -T -r -c -u ping.pcap curl.pcapcapinfos -T -m -Q -c -u -e ping.pcap curl.pcapcapinfos -M -c -d -i -u ping.pcapcapinfos -C -c missing.pcap ping.pcap$ capinfos -T -r -c -u ping.pcap curl.pcapping.pcap 10 4.054185curl.pcap 20 1.047890$ capinfos -T -m -Q -c -u -e ping.pcap curl.pcap"File name","Number of packets","Capture dura"ping.pcap","10","4.054185","2026-11-09 03:02:39"curl.pcap","20","1.047890","2026-11-09 03:02:46$ capinfos -M -c -d -i -u ping.pcapNumber of packets: 10Data size: 980 bytesCapture duration: 4.054185 secondsData bit rate: 1933.80 bits/sec$ capinfos -C -c missing.pcap ping.pcapcapinfos: The file "missing.pcap" doesn't exist.| capinfos option | Shows |
|---|---|
| (none) / -A | Full long report |
| -c -d -u | Packet count, data size, duration |
| -a -e (-S) | First / last packet time (epoch with -S) |
| -t -E -l -s | File type, encapsulation, snaplen, file size |
| -i -y -x -z | Data rate bits/s, bytes/s, packet rate, avg packet size |
| -o | Strict time order True/False |
| -H | SHA256 + SHA1 of the file (for sharing) |
| -k / -p | Capture comment / packet comments |
| -T -m -Q -r | Table, comma, double quotes, no header (CSV: -TmQ *.pcap > caps.csv) |
| -M / -C | Raw unrounded values / stop at first error |
126.5 editcap: select and remove packets
- editcap in out copies a file; default output format is pcapng.
- A packet range (1-4) deletes those packets; -r inverts and keeps only them.
editcap ping.pcap ping.pcapngeditcap ping.pcapng no1-4.pcapng 1-4editcap -r ping.pcapng first4.pcapng 1-4$ capinfos -t -c ping.pcapngFile type: Wireshark/... - pcapngNumber of packets: 10$ capinfos -c no1-4.pcapngNumber of packets: 6$ tcpdump -nn -t -r first4.pcapngIP 192.168.146.10 > 192.168.146.20: ICMP echo requestIP 192.168.146.20 > 192.168.146.10: ICMP echo replyIP 192.168.146.10 > 192.168.146.20: ICMP echo requestIP 192.168.146.20 > 192.168.146.10: ICMP echo reply126.6 editcap: split output
- -c 4: at most 4 packets per file (10 packets -> 3 files).
- -i 2: each file covers 2 seconds; sequence number and start time are added to the name.
editcap -c 4 ping.pcapng part.pcapngeditcap -i 2 ping.pcapng win.pcapng$ capinfos -T -c part_*part_00000_20261109030235.pcapng 4part_00001_20261109030237.pcapng 4part_00002_20261109030239.pcapng 2$ capinfos -T -c win_*win_00000_20261109030235.pcapng 4win_00001_20261109030237.pcapng 4win_00002_20261109030239.pcapng 2126.7 editcap: format and truncation
- -F alone lists all formats; -F pcap converts back to classic pcap.
- -s 64 truncates every packet to 64 bytes: inferred snaplen 64, but data size still shows the original wire length.
editcap -Feditcap -F pcap ping.pcapng back.pcapeditcap -s 64 curl.pcap snap64.pcapngcapinfos -l -d curl.pcap snap64.pcapng$ editcap -Feditcap: The available capture file types for the "-F" flag are: pcap - Wireshark/tcpdump/... - pcap pcapng - Wireshark/... - pcapng 5views - InfoVista 5View capture btsnoop - Symbian OS btsnoop erf - Endace ERF capture$ capinfos -l -d curl.pcap snap64.pcapngFile name: curl.pcapPacket size limit: file hdr: 262144 bytesData size: 1522 bytesFile name: snap64.pcapngPacket size limit: inferred: 64 bytesData size: 1522 bytes126.8 editcap: timestamps
- -t 3600 shifts all timestamps one hour ahead; -t -0.5 moves them half a second back.
- Use it when the capture machine's clock was wrong before merging files.
editcap -t 3600 ping.pcapng later.pcapngeditcap -t -0.5 ping.pcapng earlier.pcapng$ capinfos -a -e ping.pcapng later.pcapngFile name: ping.pcapngFirst packet time: 2026-11-09 03:02:35.005683Last packet time: 2026-11-09 03:02:39.059868File name: later.pcapngFirst packet time: 2026-11-09 04:02:35.005683Last packet time: 2026-11-09 04:02:39.059868$ capinfos -a earlier.pcapngFirst packet time: 2026-11-09 03:02:34.505683126.9 editcap: duplicate removal
- The same traffic captured in two places (SPAN + server) appears twice after a merge.
- -d compares length + MD5 of each packet with the previous 5 packets and drops duplicates.
- -D sets the window: D 1 skipped nothing, D 2 removed 10 duplicates (the copy is the very next packet).
mergecap -w dup.pcapng ping.pcapng ping.pcapngeditcap -d dup.pcapng dedup.pcapngeditcap -D 1 dup.pcapng d1.pcapngeditcap -D 2 dup.pcapng d2.pcapng$ capinfos -c dup.pcapngNumber of packets: 20$ editcap -d dup.pcapng dedup.pcapng20 packets seen, 10 packets skipped with duplicate window of 5 packets.$ editcap -D 1 dup.pcapng d1.pcapng20 packets seen, 0 packets skipped with duplicate window of 1 packets.$ editcap -D 2 dup.pcapng d2.pcapng20 packets seen, 10 packets skipped with duplicate window of 2 packets.- Step 1
1.mergecap ping + ping -> dup.pcapng (20 packets, each twice)
- Step 2
2.editcap -d reads a packet and computes length + MD5
- Step 3
3.Compares with the last N packets (window)
- Step 4
4.Match -> skip; no match -> write
- Step 5
5.dedup.pcapng: 10 packets
126.10 editcap: comments, secrets and other options
editcap --capture-comment \ 'n126 lab: ping cli to web' \ -a '1:first echo request' \ ping.pcapng commented.pcapngcapinfos -k commented.pcapngcapinfos -p commented.pcapngeditcap --inject-secrets helpeditcap -V -D 0 ping.pcapng /dev/null$ capinfos -k commented.pcapngCapture comment: n126 lab: ping cli to web$ capinfos -p commented.pcapngPacket 1 Comment: first echo request$ editcap --inject-secrets help tls ssh wg$ editcap -V -D 0 ping.pcapng /dev/nullFile ping.pcapng is a Wireshark/... - pcapng capture file.Packet: 1, Len: 98, MD5 Hash: 3f5fd55b5eb1f376414730e4c5c4786fPacket: 2, Len: 98, MD5 Hash: 96a352290f3e5a7385d5e489ee5382aePacket: 3, Len: 98, MD5 Hash: 6a2237400afba9a1c2bef75f2e1d3663| editcap option | Does |
|---|---|
| 1-4 / -r 1-4 | Delete packets 1-4 / keep only 1-4 |
| -A / -B time | Keep only a time window (incident analysis) |
| -c N / -i sec | Split by packet count / by seconds |
| -F pcap / -T ether | Output format / force encapsulation |
| -s 64 / -C 14 | Truncate to 64 bytes / cut bytes from start (-C -4 from end) |
| -t sec / -S 0 | Shift timestamps / fix out-of-order times |
| -d / -D N / -w sec | Remove duplicates (window 5 / N packets / time window) |
| --capture-comment / -a N:text | File comment / packet comment |
| --inject-secrets tls,keys.log | Embed TLS/SSH/WireGuard keys in pcapng |
| -E 0.02 --seed | Fuzzing: corrupt random bytes |
126.11 mergecap
- -w output is required.
- Default: merge in timestamp order, so ping packets come first even though curl.pcap is listed first (strict time order True).
- -a just concatenates files in the given order (time order False).
- -F pcap sets the output format; -w - writes to stdout for a pipe into tshark; -V shows progress; -I controls pcapng interface block merging.
mergecap -w all.pcapng curl.pcap ping.pcapngmergecap -a -w joined.pcapng curl.pcap ping.pcapngmergecap -F pcap -w merged.pcap curl.pcap ping.pcapng$ capinfos -c -o all.pcapngNumber of packets: 30Strict time order: True$ tcpdump -nn -tttt -r all.pcapng | head -12026-11-09 03:02:35.005683 IP 192.168.146.10 > 192.168.146.20: ICMP echo request$ capinfos -c -o joined.pcapngNumber of packets: 30Strict time order: False$ tcpdump -nn -tttt -r joined.pcapng | head -12026-11-09 03:02:44.979864 IP 192.168.146.10.51726 > 192.168.146.20.80: Flags [S]$ capinfos -t -c merged.pcapFile type: Wireshark/tcpdump/... - pcapNumber of packets: 30126.12 Common mistakes
- Expecting data size to shrink after -s: capinfos counts the original wire length; check -l (inferred 64 bytes).
- Merging with -a when you want a timeline: use the default time-order merge.
- Merging captures from machines with different clocks without fixing them first (editcap -t).
- Forgetting that output is pcapng by default when an old tool needs pcap.
126.13 Interview tips
- Big capture: capinfos (packets, duration, start/end) -> editcap -A/-B time window or -c split -> analyse.
- Firewall clock 2 s behind: editcap -t 2 fw.pcapng fw-fixed.pcapng, then mergecap -w all.pcapng fw-fixed.pcapng srv.pcapng.
- Duplicate packets after merging SPAN + host captures: editcap -d (or -D N).
- capinfos -H gives a hash to prove a shared capture was not changed.