This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Import from plain text file

0
1

I know Wireshark has an option to export packets into a plain text file. How can I achieve the opposite? I know that Wireshark cannot read text files directly, but can someone point me in the direction of how to modify the text file such that Wireshark can read and import it?

asked 05 Sep '15, 10:58

xeek's gravatar image

xeek
6122
accept rate: 0%


One Answer:

0

Wireshark has menu items (under "Export Packet DIssections") to export the summary lines, detailed packet dissections, or raw hex dump of packets to plain text files.

The only text files Wireshark could import would be text files containing hex dumps of raw packet data; there is no capability to read detailed packet dissections and attempt to figure out what the raw packet data would be for them.

Wireshark's capability to import text files is similar to what its text2pcap program provides; the text2pcap man page says:

   Text2pcap understands a hexdump of the form generated by od −Ax −tx1
   −v.  In other words, each byte is individually displayed, with spaces
   separating the bytes from each other.  Each line begins with an offset
   describing the position in the file, with a space separating it from
   the following bytes.  The offset is a hex number (can also be octal or
   decimal − see −o), of more than two hex digits. Here is a sample dump
   that text2pcap can recognize:

000000 00 0e b6 00 00 02 00 0e b6 00 00 01 08 00 45 00 000010 00 28 00 00 00 00 ff 01 37 d1 c0 00 02 01 c0 00 000020 02 02 08 00 a6 2f 00 01 00 01 48 65 6c 6c 6f 20 000030 57 6f 72 6c 64 21 000036

There is no limit on the width or number of bytes per line. Also the text dump at the end of the line is ignored. Bytes/hex numbers can be uppercase or lowercase. Any text before the offset is ignored, including email forwarding characters ’>’. Any lines of text between the bytestring lines is ignored. The offsets are used to track the bytes, so offsets must be correct. Any line which has only bytes without a leading offset is ignored. An offset is recognized as being a hex number longer than two characters. Any text after the bytes is ignored (e.g. the character dump). Any hex numbers in this text are also ignored. An offset of zero is indicative of starting a new packet, so a single text file with a series of hexdumps can be converted into a packet capture with multiple packets. Packets may be preceded by a timestamp. These are interpreted according to the format given on the command line (see −t). If not, the first packet is timestamped with the current time the conversion takes place. Multiple packets are written with timestamps differing by one microsecond each. In general, short of these restrictions, text2pcap is pretty liberal about reading in hexdumps and has been tested with a variety of mangled outputs (including being forwarded through email multiple times, with limited line wrap etc.)

There are a couple of other special features to note. Any line where the first non‐whitespace character is ’#’ will be ignored as a comment. Any line beginning with #TEXT2PCAP is a directive and options can be inserted after this command to be processed by text2pcap. Currently there are no directives implemented; in the future, these may be used to give more fine grained control on the dump and the way it should be processed e.g. timestamps, encapsulation type etc.

Text2pcap also allows the user to read in dumps of application‐level data, by inserting dummy L2, L3 and L4 headers before each packet. The user can elect to insert Ethernet headers, Ethernet and IP, or Ethernet, IP and UDP/TCP/SCTP headers before each packet. This allows Wireshark or any other full‐packet decoder to handle these dumps.

The time stamp format and “dumps of application-level data” stuff is, in Wireshark, controlled by fields in the “Import from Hex Dump…” dialog.

answered 05 Sep ‘15, 11:48

Guy%20Harris's gravatar image

Guy Harris ♦♦
17.4k335196
accept rate: 19%