1 include::../attributes.adoc[]
6 :copycss: {css_dir}/{stylesheet}
10 text2pcap - Generate a capture file from an ASCII hexdump of packets
20 [ *-E* <encapsulation type> ]
21 [ *-F* <file format> ]
26 [ *-o* hex|oct|dec|none ]
29 [ *-s* <srcport>,<destport>,<tag> ]
30 [ *-S* <srcport>,<destport>,<ppi> ]
32 [ *-T* <srcport>,<destport> ]
33 [ *-u* <srcport>,<destport> ]
34 [ *-4* <srcip>,<destip> ]
35 [ *-6* <srcip>,<destip> ]
49 *Text2pcap* is a program that reads in an ASCII hex dump and writes the
50 data described into a capture file. *text2pcap* can read hexdumps with
51 multiple packets in them, and build a capture file of multiple packets.
52 *Text2pcap* is also capable of generating dummy Ethernet, IP, and UDP, TCP
53 or SCTP headers, in order to build fully processable packet dumps from
54 hexdumps of application-level data only.
56 *Text2pcap* can write the file in several output formats.
57 The *-F* flag can be used to specify the format in which to write the
58 capture file, *text2pcap -F* provides a list of the available output
59 formats. By default, it writes the packets to __outfile__ in the *pcapng*
60 file format. *Text2cap* also supports compression formats, which can
61 be specified with the *--compress* options. If that option is not given,
62 the the desired compression method, if any, is deduced from the extension
63 of __outfile__; e.g. if it has the extension '.gz', then the output file
64 is compressed to a gzip archive.
66 *Text2pcap* understands a hexdump of the form generated by __od -Ax
67 -tx1 -v__. In other words, each byte is individually displayed, with
68 spaces separating the bytes from each other. Hex digits can be upper
71 In normal operation, each line must begin with an offset describing the
72 position in the packet, followed a colon, space, or tab separating it from
73 the bytes. There is no limit on the width or number of bytes per line, but
74 lines with only hex bytes without a leading offset are ignored (in other words,
75 line breaks should not be inserted in long lines that wrap.) Offsets are more
76 than two digits; they are in hex by default, but can also be in octal or
77 decimal - see *-o*. Each packet must begin with offset zero, and an offset
78 zero indicates the beginning of a new packet. Offset values must be correct;
79 an unexpected value causes the current packet to be aborted and the next
80 packet start awaited. There is also a single packet mode with no offsets;
83 Packets may be preceded by a direction indicator ('I' or 'O') and/or a
84 timestamp if indicated by the command line (see *-D* and *-t*). If both are
85 present, the direction indicator precedes the timestamp. The format of the
86 timestamps is specified as a mandatory parameter to *-t*. If no timestamp is
87 parsed, in the case of the first packet the current system time is used, while
88 subsequent packets are written with timestamps one microsecond later than that
89 of the previous packet.
91 Other text in the input data is ignored. Any text before the offset is
92 ignored, including email forwarding characters '>'. Any text on a line
93 after the bytes is ignored, e.g. an ASCII character dump (but see *-a* to
94 ensure that hex digits in the character dump are ignored). Any line where
95 the first non-whitespace character is a '#' will be ignored as a comment.
96 Any lines of text between the bytestring lines are considered preamble;
97 the beginning of the preamble is scanned for the direction indicator and
98 timestamp as mentioned above and otherwise ignored.
100 Any line beginning with #TEXT2PCAP is a directive and options
101 can be inserted after this command to be processed by *text2pcap*.
102 Currently there are no directives implemented; in the future, these may
103 be used to give more fine grained control on the dump and the way it
104 should be processed e.g. timestamps, encapsulation type etc.
106 In general, short of these restrictions, *text2pcap* is pretty liberal
107 about reading in hexdumps and has been tested with a variety of
108 mangled outputs (including being forwarded through email multiple
109 times, with limited line wrap etc.)
111 Here is a sample dump that *text2pcap* can recognize, with optional
112 directional indicator and timestamp:
114 I 2019-05-14T19:04:57Z
115 000000 00 0e b6 00 00 02 00 0e b6 00 00 01 08 00 45 00
116 000010 00 28 00 00 00 00 ff 01 37 d1 c0 00 02 01 c0 00
117 000020 02 02 08 00 a6 2f 00 01 00 01 48 65 6c 6c 6f 20
118 000030 57 6f 72 6c 64 21
121 *Text2pcap* is also capable of scanning a text input file using a custom Perl
122 compatible regular expression that matches a single packet. *text2pcap*
123 searches the given file (which must end with '\n') for non-overlapping non-empty
124 strings matching the regex. Named capturing subgroups, which must match
125 exactly once per packet, are used to identify fields to import. The following
126 fields are supported in regex mode, one mandatory and three optional:
128 "data" Actual captured frame data to import
129 "time" Timestamp of packet
130 "dir" Direction of packet
131 "seqno" Arbitrary ID of packet
133 The 'data' field is the captured data, which must be in a selected encoding:
134 hexadecimal (the default), octal, binary, or base64 and containing no
135 characters in the data field outside the encoding set besides whitespace.
136 The 'time' field is parsed according to the format in the *-t* parameter.
137 The first character of the 'dir' field is compared against a set of characters
138 corresponding to inbound and outbound that default to "iI<" for inbound and
139 "oO>" for outbound to assign a direction. The 'seqno' field is assumed to
140 be a positive integer base 10 used for an arbitrary ID. An optional field's
141 information will only be written if the field is present in the regex and if
142 the capture file format supports it. (E.g., the pcapng format supports all
143 three fields, but the pcap format only supports timestamps.)
145 Here is a sample dump that the regex mode can process with the regex
146 '^(?<dir>[<>])\s(?<time>\d+:\d\d:\d\d.\d+)\s(?<data>[0-9a-fA-F]+)$' along
147 with timestamp format '%H:%M:%S.%f', directional indications of '<' and '>',
150 > 0:00:00.265620 a130368b000000080060
151 > 0:00:00.280836 a1216c8b00000000000089086b0b82020407
152 < 0:00:00.295459 a2010800000000000000000800000000
153 > 0:00:00.296982 a1303c8b00000008007088286b0bc1ffcbf0f9ff
154 > 0:00:00.305644 a121718b0000000000008ba86a0b8008
155 < 0:00:00.319061 a2010900000000000000001000600000
156 > 0:00:00.330937 a130428b00000008007589186b0bb9ffd9f0fdfa3eb4295e99f3aaffd2f005
157 > 0:00:00.356037 a121788b0000000000008a18
159 The regex is compiled with multiline support, and it is recommended to use
160 the anchors '^' and '$' for best results.
162 *Text2pcap* also allows the user to read in dumps of application-level
163 data and insert dummy L2, L3 and L4 headers before each packet. This allows
164 Wireshark or any other full-packet decoder to handle these dumps.
165 If the encapsulation type is Ethernet, the user can elect to insert Ethernet
166 headers, Ethernet and IP, or Ethernet, IP and UDP/TCP/SCTP headers before
167 each packet. The fake headers can also be used with the Raw IP, Raw IPv4,
168 or Raw IPv6 encapsulations, with the Ethernet header omitted. These
169 encapsulation options can be used in both hexdump mode and regex mode.
171 When <__infile__> or <__outfile__> are '-', standard input or standard
172 output, respectively, are used.
179 Enables ASCII text dump identification. It allows one to identify the start of
180 the ASCII text dump and not include it in the packet even if it looks like HEX.
181 This parameter has no effect in regex mode.
183 *NOTE:* Do not enable it if the input file does not contain the ASCII text dump.
189 Specify the base (radix) of the encoding of the packet data in regex mode.
190 The supported options are 2 (binary), 8 (octal), 16 (hexadecimal), and 64
191 (base64 encoding), with hex as the default. This parameter has no effect
198 Indicates that the text before each input packet may start either with an I
199 or O indicating that the packet is inbound or outbound. If both this flag
200 and the __t__ flag are used, the directional indicator is expected before
202 This parameter has no effect in regex mode, where the presence of the `<dir>`
203 capturing group determines whether direction indicators are expected.
205 Direction indication is stored in the packet headers if the output format
206 supports it (e.g. pcapng), and is also used when generating dummy headers
207 to swap the source and destination addresses and ports as appropriate.
213 Include a dummy Ethernet header before each packet. Specify the EtherType
214 for the Ethernet header in hex. Use this option if your dump has Layer
215 3 header and payload (e.g. IP header), but no Layer 2
216 encapsulation. Example: __-e 0x806__ to specify an ARP packet.
218 For IP packets, instead of generating a fake Ethernet header you can
219 also use __-E rawip__ or __-l 101__ to indicate raw IP encapsulation.
220 Note that raw IP encapsulation does not work for any non-IP Layer 3 packet
221 (e.g. ARP), whereas generating a dummy Ethernet header with __-e__ works
222 for any sort of L3 packet.
225 -E <encapsulation type>::
228 Sets the packet encapsulation type of the output capture file.
229 *text2pcap -E* provides a list of the available types; note that not
230 all file formats support all encapsulation types. The default type is
233 *NOTE:* This sets the encapsulation type of the output file, but does
234 not translate the packet headers or add additional headers. It is used
235 to specify the encapsulation that matches the input data.
241 Sets the file format of the output capture file. *Text2pcap* can write
242 the file in several formats; *text2pcap -F* provides a list of the
243 available output formats. The default is the *pcapng* format.
247 Print the version number and options and exit.
252 Include dummy IP headers before each packet. Specify the IP protocol
253 for the packet in decimal. Use this option if your dump is the payload
254 of an IP packet (i.e. has complete L4 information) but does not have
255 an IP header with each packet. Note that an appropriate Ethernet header
256 is automatically included with each packet as well if the link-layer
258 Example: __-i 46__ to specify an RSVP packet (IP protocol 46). See
259 https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml for
260 the complete list of assigned internet protocol numbers.
266 Sets the packet encapsulation type of the output capture file, using
267 pcap link-layer header type numbers. Default is Ethernet (1).
268 See https://www.tcpdump.org/linktypes.html for the complete list
269 of possible encapsulations.
270 Example: __-l 7__ for ARCNet packets encapsulated BSD-style.
276 Set the maximum packet length, default is 262144.
277 Useful for testing various packet boundaries when only an application
278 level datastream is available. Example:
280 __od -Ax -tx1 -v stream | text2pcap -m1460 -T1234,1234 - stream.pcap__
282 will convert from plain datastream format to a sequence of Ethernet
287 Specify a name for the interface included when writing a pcapng format file.
289 -o hex|oct|dec|none::
292 Specify the radix for the offsets (hex, octal, decimal, or none). Defaults to
293 hex. This corresponds to the `-A` option for __od__. This parameter has no
294 effect in regex mode.
296 *NOTE:* With __-o none__, only one packet will be created, ignoring any
297 direction indicators or timestamps after the first byte along with any offsets.
303 Include an EXPORTED_PDU header before each packet. Specify, as a
304 string, the dissector to be called for the packet (DISSECTOR_NAME tag).
305 Use this option if your dump is the payload for a single upper layer
306 protocol (so specifying a link layer type would not work) and you wish
307 to create a capture file without a full dummy protocol stack.
308 Automatically sets the link layer type to Wireshark Upper PDU export.
309 Without this option, if the Upper PDU export link layer type (252) is
310 selected the dissector defaults to "data".
314 Don't display the summary of the options selected at the beginning, or the count of packets processed at the end.
319 Process the file in regex mode using __regex__ as described above.
321 *NOTE:* The regex mode uses memory-mapped I/O and does not work on
322 streams that do not support seeking, like terminals and pipes.
325 -s <srcport>,<destport>,<tag>::
328 Include dummy SCTP headers before each packet. Specify, in decimal, the
329 source and destination SCTP ports, and verification tag, for the packet.
330 Use this option if your dump is the SCTP payload of a packet but does
331 not include any SCTP, IP or Ethernet headers. Note that appropriate
332 Ethernet and IP headers are automatically also included with each
333 packet. A CRC32C checksum will be put into the SCTP header.
336 -S <srcport>,<destport>,<ppi>::
339 Include dummy SCTP headers before each packet. Specify, in decimal, the
340 source and destination SCTP ports, and a verification tag of 0, for the
341 packet, and prepend a dummy SCTP DATA chunk header with a payload
342 protocol identifier if __ppi__. Use this option if your dump is the SCTP
343 payload of a packet but does not include any SCTP, IP or Ethernet
344 headers. Note that appropriate Ethernet and IP headers are
345 automatically included with each packet. A CRC32C checksum will be put
346 into the SCTP header.
352 Treats the text before the packet as a date/time code; __timefmt__ is a
353 format string supported by strftime(3), supplemented with the field
354 descriptor '%f' for fractional seconds up to nanoseconds.
355 Example: The time "10:15:14.5476" has the format code "%H:%M:%S.%f"
356 The special format string __ISO__ indicates that the string should be
357 parsed according to the ISO-8601 specification. This parameter is used
358 in regex mode if and only if the `<time>` capturing group is present.
360 *NOTE:* Date/time fields from the current date/time are
361 used as the default for unspecified fields.
364 -T <srcport>,<destport>::
367 Include dummy TCP headers before each packet. Specify the source and
368 destination TCP ports for the packet in decimal. Use this option if
369 your dump is the TCP payload of a packet but does not include any TCP,
370 IP or Ethernet headers. Note that appropriate Ethernet and IP headers
371 are automatically also included with each packet.
372 Sequence numbers will start at 0.
375 -u <srcport>,<destport>::
378 Include dummy UDP headers before each packet. Specify the source and
379 destination UDP ports for the packet in decimal. Use this option if
380 your dump is the UDP payload of a packet but does not include any UDP,
381 IP or Ethernet headers. Note that appropriate Ethernet and IP headers
382 are automatically also included with each packet.
383 Example: __-u1000,69__ to make the packets look like TFTP/UDP packets.
387 Print the full version information and exit.
389 -4 <srcip>,<destip>::
392 Prepend dummy IP header with specified IPv4 source and destination addresses.
393 This option should be accompanied by one of the following options: -i, -s, -S, -T, -u
394 Use this option to apply "custom" IP addresses.
395 Example: __-4 10.0.0.1,10.0.0.2__ to use 10.0.0.1 and 10.0.0.2 for all IP packets.
398 -6 <srcip>,<destip>::
401 Prepend dummy IP header with specified IPv6 source and destination addresses.
402 This option should be accompanied by one of the following options: -i, -s, -S, -T, -u
403 Use this option to apply "custom" IP addresses.
404 Example: __-6 2001:db8::b3ff:fe1e:8329,2001:0db8:85a3::8a2e:0370:7334__ to
405 use 2001:db8::b3ff:fe1e:8329 and 2001:0db8:85a3::8a2e:0370:7334 for all IP packets.
411 Compress the output file using the type compression format.
412 *--compress* with no argument provides a list of the compression formats supported
413 for writing. The type given takes precedence over the extension of __outfile__.
416 include::diagnostic-options.adoc[]
420 od(1), xref:https://www.tcpdump.org/manpages/pcap.3pcap.html[pcap](3), xref:wireshark.html[wireshark](1), xref:tshark.html[tshark](1), xref:dumpcap.html[dumpcap](1), xref:mergecap.html[mergecap](1),
421 xref:editcap.html[editcap](1), strftime(3), 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)
425 This is the manual page for *Text2pcap* {wireshark-version}.
426 *Text2pcap* is part of the *Wireshark* distribution.
427 The latest version of *Wireshark* can be found at https://www.wireshark.org.
433 Ashok Narayanan <ashokn[AT]cisco.com>