1 include::../attributes.adoc[]
6 :copycss: {css_dir}/{stylesheet}
10 editcap - Edit and/or translate the format of capture files
16 [ *-a* <frame:comment> ]
19 [ *-c* <packets per file> ]
20 [ *-C* [offset:]<choplen> ]
21 [ *-E* <error probability> ]
22 [ *-F* <file format> ]
23 [ *-i* <seconds per file> ]
24 [ *-o* <change offset> ]
28 [ *-S* <strict time adjustment> ]
29 [ *-t* <time adjustment> ]
30 [ *-T* <encapsulation type> ]
32 [ *--inject-secrets* <secrets type>,<file> ]
33 [ *--discard-all-secrets* ]
34 [ *--capture-comment* <comment> ]
35 [ *--discard-capture-comment* ]
36 [ *--discard-packet-comments* ]
39 [ __packet#__[-__packet#__] ... ]
45 *-w* <dup time window>
47 [ *-I* <bytes to ignore> ]
48 [ *--skip-radiotap-header* ]
70 *Editcap* is a program that reads some or all of the captured packets from the
71 __infile__, optionally converts them in various ways and writes the
72 resulting packets to the capture __outfile__ (or outfiles).
74 By default, it reads all packets from the __infile__ and writes them to the
75 __outfile__ in pcapng file format. Use '-' for __infile__ or __outfile__
76 to read from standard input or write to standard output, respectively.
78 The *-A* and *-B* option allow you to limit the time range from which packets
79 are read from the __infile__.
81 An optional list of packet numbers can be specified on the command tail;
82 individual packet numbers separated by whitespace and/or ranges of packet
83 numbers can be specified as __start__-__end__, referring to all packets from
84 __start__ to __end__. By default the selected packets with those numbers will
85 __not__ be written to the capture file. If the *-r* flag is specified, the
86 whole packet selection is reversed; in that case __only__ the selected packets
87 will be written to the capture file.
89 *Editcap* can also be used to remove duplicate packets. Several different
90 options (*-d*, *-D* and *-w*) are used to control the packet window
91 or relative time window to be used for duplicate comparison.
93 *Editcap* can be used to assign comment strings to frame numbers.
95 *Editcap* is able to detect, read and write the same capture files that
96 are supported by *Wireshark*.
97 The input file doesn't need a specific filename extension; the file
98 format and an optional gzip, zstd or lz4 compression will be automatically detected.
99 Near the beginning of the DESCRIPTION section of xref:wireshark.html[wireshark](1) or
100 https://www.wireshark.org/docs/man-pages/wireshark.html
101 is a detailed description of the way *Wireshark* handles this, which is
102 the same way *Editcap* handles this.
104 *Editcap* can write the file in several output formats. The *-F*
105 flag can be used to specify the format in which to write the capture
106 file; *editcap -F* provides a list of the available output formats.
107 *Editcap* can also compress the output file. The *--compress* option
108 can specify the compression type. If that option is not given, then the desired
109 compression method, if any, is deduced from the extension of __outfile__;
110 e.g., if the output filename has the .gz extension, then the gzip format is used.
112 *Editcap* can also be used to extract embedded decryption secrets from file
113 formats like *pcapng* that contain them, in lieu of writing a capture file.
117 -a <framenum:comment>::
120 For the specified frame number, assign the given comment string.
121 Can be repeated for multiple frames. Quotes should be used with comment
122 strings that include spaces.
128 Reads only the packets whose timestamp is on or after <start time>.
129 The time may be given either in ISO 8601 format or in Unix epoch
132 ISO 8601 format is either
134 YYYY-MM-DD HH:MM:SS[.nnnnnnnnn][Z|±hh:mm]
138 YYYY-MM-DDTHH:MM:SS[.nnnnnnnnn][Z|±hh:mm]
140 The fractional seconds are optional, as is the time zone offset from UTC
141 (in which case local time is assumed).
143 Unix epoch format is in seconds since the Unix epoch and nanoseconds,
144 with either a period or a comma separating the seconds and nanoseconds.
145 The nanoseconds are optional.
146 The Unix epoch is 1970-01-01 00:00:00 UTC, so this format is not local
153 Reads only the packets whose timestamp is before <stop time>.
154 The time may be given either in ISO 8601 format or in Unix epoch
157 ISO 8601 format is either
159 YYYY-MM-DD HH:MM:SS[.nnnnnnnnn][Z|±hh:mm]
163 YYYY-MM-DDTHH:MM:SS[.nnnnnnnnn][Z|±hh:mm]
165 The fractional seconds are optional, as is the time zone offset from UTC
166 (in which case local time is assumed).
168 Unix epoch format is in seconds since the Unix epoch and nanoseconds,
169 with either a period or a comma separating the seconds and nanoseconds.
170 The nanoseconds are optional.
171 The Unix epoch is 1970-01-01 00:00:00 UTC, so this format is not local
175 -c <packets per file>::
178 Splits the packet output to different files based on uniform packet counts
179 with a maximum of <packets per file> each.
181 Each output file will be created with an infix _nnnnn[_YYYYmmddHHMMSS] inserted
182 before the file extension (which may be null) of __outfile__. The infix
183 consists of the ordinal number of the output file, starting with 00000,
184 followed by the timestamp of its first packet. The timestamp is omitted if
185 the input file does not contain timestamp information.
187 After the specified number of packets is written to the output file, the next
188 output file is opened. The default is to use a single output file.
189 This option conflicts with *-i*.
192 -C [offset:]<choplen>::
195 Sets the chop length to use when writing the packet data. Each packet is
196 chopped by <choplen> bytes of data. Positive values chop at the packet
197 beginning while negative values chop at the packet end.
199 If an optional offset precedes the <choplen>, then the bytes chopped will be
200 offset from that value. Positive offsets are from the packet beginning, while
201 negative offsets are from the packet end.
203 This is useful for chopping headers for decapsulation of an entire capture,
204 removing tunneling headers, or in the rare case that the conversion between two
205 file formats leaves some random bytes at the end of each packet. Another use is
206 for removing vlan tags.
208 NOTE: This option can be used more than once, effectively allowing you to chop
209 bytes from up to two different areas of a packet in a single pass provided that
210 you specify at least one chop length as a positive value and at least one as a
211 negative value. All positive chop lengths are added together as are all
212 negative chop lengths.
218 Attempts to remove duplicate packets. The length and MD5 hash of the
219 current packet are compared to the previous four (4) packets. If a
220 match is found, the current packet is skipped. This option is equivalent
221 to using the option *-D 5*.
227 Attempts to remove duplicate packets. The length and MD5 hash of the
228 current packet are compared to the previous <dup window> - 1 packets.
229 If a match is found, the current packet is skipped.
231 The use of the option *-D 0* combined with the *-V* option is useful
232 in that each packet's Packet number, Len and MD5 Hash will be printed
233 to standard error. This verbose output (specifically the MD5 hash strings)
234 can be useful in scripts to identify duplicate packets across trace
237 The <dup window> is specified as an integer value between 0 and 1000000 (inclusive).
239 NOTE: Specifying large <dup window> values with large tracefiles can
240 result in very long processing times for *editcap*.
243 -E <error probability>::
246 Sets the probability that bytes in the output file are randomly changed.
247 *Editcap* uses that probability (between 0.0 and 1.0 inclusive)
248 to apply errors to each data byte in the file. For instance, a
249 probability of 0.02 means that each byte has a 2% chance of having an error.
251 This option is meant to be used for fuzz-testing protocol dissectors.
257 Sets the file format of the output capture file.
258 *Editcap* can write the file in several formats, *editcap -F*
259 provides a list of the available output formats. The default
260 is the *pcapng* format.
264 Print the version number and options and exit.
266 -i <seconds per file>::
269 Splits the packet output to different files based on uniform time
270 intervals using a maximum interval of <seconds per file> each. Floating
271 point values (e.g. 0.5) are allowed.
273 Each output file will be created with an infix _nnnnn[_YYYYmmddHHMMSS] inserted
274 before the file extension (which may be null) of __outfile__. The infix
275 consists of the ordinal number of the output file, starting with 00000,
276 followed by the timestamp of its first packet. The timestamp is omitted if
277 the input file does not contain timestamp information.
279 After packets for the specified time interval are written to the output file,
280 the next output file is opened. The default is to use a single output file.
281 This option conflicts with *-c*.
284 -I <bytes to ignore>::
287 Ignore the specified number of bytes at the beginning of the frame during MD5 hash calculation,
288 unless the frame is too short, then the full frame is used.
289 Useful to remove duplicated packets taken on several routers (different mac addresses for example)
290 e.g. -I 26 in case of Ether/IP will ignore ether(14) and IP header(20 - 4(src ip) - 4(dst ip)).
291 The default value is 0.
297 Adjust the original frame length accordingly when chopping and/or snapping
298 (in addition to the captured length, which is always adjusted regardless of
299 whether *-L* is specified or not). See also *-C <choplen*> and *-s <snaplen*>.
305 When used in conjunction with -E, skip some bytes from the beginning of the packet
306 from being changed. In this way some headers don't get changed, and the fuzzer is
307 more focused on a smaller part of the packet. Keeping a part of the packet fixed
308 the same dissector is triggered, that make the fuzzing more precise.
314 Reverse the packet selection.
315 Causes the packets whose packet numbers are specified on the command
316 line to be written to the output capture file, instead of discarding them.
322 Sets the snapshot length to use when writing the data.
323 If the *-s* flag is used to specify a snapshot length, packets in the
324 input file with more captured data than the specified snapshot length
325 will have only the amount of data specified by the snapshot length
326 written to the output file.
328 This may be useful if the program that is
329 to read the output file cannot handle packets larger than a certain size
330 (for example, the versions of snoop in Solaris 2.5.1 and Solaris 2.6
331 appear to reject Ethernet packets larger than the standard Ethernet MTU,
332 making them incapable of handling gigabit Ethernet captures if jumbo
339 When used in conjunction with -E, set the seed for the pseudo-random number generator.
340 This is useful for recreating a particular sequence of errors.
343 --skip-radiotap-header::
346 Skip the radiotap header of each frame when checking for packet duplicates. This is useful
347 when processing a capture created by combining outputs of multiple capture devices on the same
348 channel in the vicinity of each other.
351 -S <strict time adjustment>::
354 Time adjust selected packets to ensure strict chronological order.
356 The <strict time adjustment> value represents relative seconds
357 specified as [-]__seconds__[__.fractional seconds__].
359 As the capture file is processed each packet's absolute time is
360 __possibly__ adjusted to be equal to or greater than the previous
361 packet's absolute timestamp depending on the <strict time
364 If <strict time adjustment> value is 0 or greater (e.g. 0.000001)
365 then *only* packets with a timestamp less than the previous packet
366 will adjusted. The adjusted timestamp value will be set to be
367 equal to the timestamp value of the previous packet plus the value
368 of the <strict time adjustment> value. A <strict time adjustment>
369 value of 0 will adjust the minimum number of timestamp values
370 necessary to ensure that the resulting capture file is in
371 strict chronological order.
373 If <strict time adjustment> value is specified as a
374 negative value, then the timestamp values of *all*
375 packets will be adjusted to be equal to the timestamp value
376 of the previous packet plus the absolute value of the
377 <strict time adjustment> value. A <strict time
378 adjustment> value of -0 will result in all packets
379 having the timestamp value of the first packet.
381 This feature is useful when the trace file has an occasional
382 packet with a negative delta time relative to the previous
386 -t <time adjustment>::
389 Sets the time adjustment to use on selected packets.
390 If the *-t* flag is used to specify a time adjustment, the specified
391 adjustment will be applied to all selected packets in the capture file.
392 The adjustment is specified as [-]__seconds__[__.fractional seconds__].
393 For example, *-t* 3600 advances the timestamp on selected packets by one
394 hour while *-t* -0.5 reduces the timestamp on selected packets by
397 This feature is useful when synchronizing dumps
398 collected on different machines where the time difference between the
399 two machines is known or can be estimated.
402 -T <encapsulation type>::
405 Sets the packet encapsulation type of the output capture file.
406 If the *-T* flag is used to specify an encapsulation type, the
407 encapsulation type of the output capture file will be forced to the
409 *editcap -T* provides a list of the available types. The default
410 type is the one appropriate to the encapsulation type of the input
414 forces the encapsulation type of the output file to be the specified
415 type; the packet headers of the packets will not be translated from the
416 encapsulation type of the input capture file to the specified
417 encapsulation type (for example, it will not translate an Ethernet
418 capture to an FDDI capture if an Ethernet capture is read and '*-T
419 fddi*' is specified). If you need to remove/add headers from/to a
420 packet, you will need od(1)/xref:text2pcap.html[text2pcap](1).
424 Print the full version information and exit.
429 Causes *editcap* to print verbose messages while it's working.
431 Use of *-V* with the de-duplication switches of *-d*, *-D* or *-w*
432 will cause all MD5 hashes to be printed whether the packet is skipped
436 -w <dup time window>::
439 Attempts to remove duplicate packets. The current packet's arrival time
440 is compared with up to 1000000 previous packets. If the packet's relative
441 arrival time is __less than or equal to__ the <dup time window> of a previous packet
442 and the packet length and MD5 hash of the current packet are the same then
443 the packet to skipped. The duplicate comparison test stops when
444 the current packet's relative arrival time is greater than <dup time window>.
446 The <dup time window> is specified as __seconds__[__.fractional seconds__].
448 The [.fractional seconds] component can be specified to nine (9) decimal
449 places (billionths of a second) but most typical trace files have resolution
450 to six (6) decimal places (millionths of a second).
452 NOTE: Specifying large <dup time window> values with large tracefiles can
453 result in very long processing times for *editcap*.
455 NOTE: The *-w* option assumes that the packets are in chronological order.
456 If the packets are NOT in chronological order then the *-w* duplication
457 removal option may not identify some duplicates.
460 --inject-secrets <secrets type>,<file>::
463 Inserts the contents of <file> into a Decryption Secrets Block (DSB)
464 within the pcapng output file. This enables decryption without requiring
465 additional configuration in protocol preferences.
467 The file format is described by <secrets type> which can be one of:
469 __opcua__ OPC UA Key Log, see https://ietf-opsawg-wg.github.io/draft-ietf-opsawg-pcap/draft-ietf-opsawg-pcapng.html#name-decryption-secrets-block +
470 __ssh__ SSH Key Log, see {wireshark-wiki-url}SSH#key-log-format +
471 __tls__ TLS Key Log, see https://tlswg.org/sslkeylogfile/draft-ietf-tls-keylogfile.html +
472 __wg__ WireGuard Key Log, see {wireshark-wiki-url}WireGuard#key-log-format
474 This option may be specified multiple times. The available options for
475 <secrets type> can be listed with *--inject-secrets help*.
481 Extracts each Decryption Secrets Block (DSB) contained within __infile__.
482 If there is only one, it is written to __outfile__ instead of a capture file.
483 If there is more than one, they are each written to unique output files named
484 with an infix _nnnnn before the file extension of __outfile__ in a manner
485 similar to the *-c* flag (unless writing to standard output.)
487 Incompatible with other options except for *-V*.
490 --discard-all-secrets::
493 Discard all decryption secrets from the input file when writing the
494 output file. Does not discard secrets added by *--inject-secrets* in
495 the same command line.
498 --capture-comment <comment>::
501 Adds the given comment to the output file, if supported by the output
502 file format. New comments will be added __after__ any comments present
503 in the input file unless *--discard-capture-comment* is also specified.
505 This option may be specified multiple times. Note that Wireshark
506 currently only displays the first comment of a capture file.
509 --discard-capture-comment::
512 Discard all capture file comments from the input file when writing the output
513 file. Does not discard comments added by *--capture-comment* in the same
520 Set the unused bytes (if any) to zero in SLL link type. Useful when when checking for duplicates.
521 As the unused bytes can be anything. When the packet traverses the device stack
522 for bonded interfaces on Linux for example.
525 --discard-packet-comments::
528 Discard all packet comments from the input file when writing the output
529 file. Does not discard comments added by *-a* in the same
536 Compress the output file using the type compression format.
537 *--compress* with no argument provides a list of the compression formats supported
538 for writing. The type given takes precedence over the extension of __outfile__.
541 include::diagnostic-options.adoc[]
545 To see more detailed description of the options use:
549 To shrink the capture file by truncating the packets at 64 bytes and writing it as Sun snoop file use:
551 editcap -s 64 -F snoop capture.pcapng shortcapture.snoop
553 To delete packet 1000 from the capture file use:
555 editcap capture.pcapng sans1000.pcapng 1000
557 To limit a capture file to packets from number 200 to 750 (inclusive) use:
559 editcap -r capture.pcapng small.pcapng 200-750
561 To get all packets from number 1-500 (inclusive) use:
563 editcap -r capture.pcapng first500.pcapng 1-500
567 editcap capture.pcapng first500.pcapng 501-9999999
569 To exclude packets 1, 5, 10 to 20 and 30 to 40 from the new file use:
571 editcap capture.pcapng exclude.pcapng 1 5 10-20 30-40
573 To select just packets 1, 5, 10 to 20 and 30 to 40 for the new file use:
575 editcap -r capture.pcapng select.pcapng 1 5 10-20 30-40
577 To remove duplicate packets seen within the prior four frames use:
579 editcap -d capture.pcapng dedup.pcapng
581 To remove duplicate packets seen within the prior four frames while skipping radiotap headers use:
583 editcap -d --skip-radiotap-header capture.pcapng dedup.pcapng
585 To remove duplicate packets seen within the prior 100 frames use:
587 editcap -D 101 capture.pcapng dedup.pcapng
589 To remove duplicate packets seen __equal to or less than__ 1/10th of a second:
591 editcap -w 0.1 capture.pcapng dedup.pcapng
593 To display the MD5 hash for all of the packets (and NOT generate any
596 editcap -V -D 0 capture.pcapng /dev/null
598 or on Windows systems
600 editcap -V -D 0 capture.pcapng NUL
602 To advance the timestamps of each packet forward by 3.0827 seconds:
604 editcap -t 3.0827 capture.pcapng adjusted.pcapng
606 To ensure all timestamps are in strict chronological order:
608 editcap -S 0 capture.pcapng adjusted.pcapng
610 To introduce 5% random errors in a capture file use:
612 editcap -E 0.05 capture.pcapng capture_error.pcapng
614 To remove vlan tags from all packets within an Ethernet-encapsulated capture
617 editcap -L -C 12:4 capture_vlan.pcapng capture_no_vlan.pcapng
619 To chop both the 10 byte and 20 byte regions from the following 75 byte packet
620 in a single pass, use any of the 8 possible methods provided below:
622 <--------------------------- 75 ---------------------------->
624 +---+-------+-----------+---------------+-------------------+
625 | 5 | 10 | 15 | 20 | 25 |
626 +---+-------+-----------+---------------+-------------------+
628 1) editcap -C 5:10 -C -25:-20 capture.pcapng chopped.pcapng
629 2) editcap -C 5:10 -C 50:-20 capture.pcapng chopped.pcapng
630 3) editcap -C -70:10 -C -25:-20 capture.pcapng chopped.pcapng
631 4) editcap -C -70:10 -C 50:-20 capture.pcapng chopped.pcapng
632 5) editcap -C 30:20 -C -60:-10 capture.pcapng chopped.pcapng
633 6) editcap -C 30:20 -C 15:-10 capture.pcapng chopped.pcapng
634 7) editcap -C -45:20 -C -60:-10 capture.pcapng chopped.pcapng
635 8) editcap -C -45:20 -C 15:-10 capture.pcapng chopped.pcapng
637 To add comment strings to the first 2 input frames, use:
639 editcap -a "1:1st frame" -a 2:Second capture.pcapng capture-comments.pcapng
643 xref:https://www.tcpdump.org/manpages/pcap.3pcap.html[pcap](3), xref:wireshark.html[wireshark](1), xref:tshark.html[tshark](1), xref:mergecap.html[mergecap](1), xref:dumpcap.html[dumpcap](1), xref:capinfos.html[capinfos](1),
644 xref:text2pcap.html[text2pcap](1), xref:reordercap.html[reordercap](1), od(1), xref:https://www.tcpdump.org/manpages/pcap-filter.7.html[pcap-filter](7) or xref:https://www.tcpdump.org/manpages/tcpdump.1.html[tcpdump](8)
648 This is the manual page for *Editcap* {wireshark-version}.
649 *Editcap* is part of the *Wireshark* distribution.
650 The latest version of *Wireshark* can be found at https://www.wireshark.org.
652 HTML versions of the Wireshark project man pages are available at
653 https://www.wireshark.org/docs/man-pages.
659 Richard Sharpe <sharpe[AT]ns.aus.com>
663 Guy Harris <guy[AT]alum.mit.edu>
664 Ulf Lamping <ulf.lamping[AT]web.de>