Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Need to convert bytearray into text2pcap format Post 303036534 by sand1234 on Monday 1st of July 2019 09:13:24 AM
Old 07-01-2019
Need to convert bytearray into text2pcap format

Hi,

I'm looking for a method to add hex increments as a first column to the following file.

Something like this:

Code:
0000
0010
0020
0030
0040
0050
0060
0070
0080
0090
00a0
00b0
00c0
00d0
00e0

I have the following logic, but am unsure how to get counter=hex value, and increment the hex value.

Can I please get some assistance around this?

Code:
$ awk 'BEGIN {counter=10} {print counter, $0; counter++}' capture.txt
10 84 78 ac 54 99 e4 bc 05 1d a2 00 62 00 c0 a2 00
11 00 fc 00 0c 29 15 6c c6 a8 9d 21 93 2b 90 81 00
12 02 6c 08 00 45 00 05 98 e5 5a 00 00 fe 11 11 ed
13 c0 a8 15 06 ac 11 3e 4d d6 d7 08 07 05 84 2d 8e
14 00 09 00 0d 60 b1 29 8d 5d 12 c8 10 32 f8 3a 00
15 00 00 00 00 01 09 00 88 d6 0f a5 f6 67 13 da 1e
16 ca da 00 17 11 38 88 c5 03 e1 00 06 06 00 00 67
17 13 da 1e 11 38 88 c5 ca da 03 e1 02 07 f0 00 00
18 01 6b 91 5d 81 06 00 00 00 00 00 00 05 24 00 00
19 00 00 00 00 1f 9d 00 00 00 00 00 00 00 1b 00 00
20 00 00 00 00 00 12 00 00 01 6b 91 5d 12 20 04 71
21 c2 50 26 5c 0a 8e 55 56 f9 1d 00 00 00 00 00 00
22 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
23 00 00 00 00 00 00 00 00 00 00 00 00 01 07 01 08
24 d6 0f 9e 69 67 13 da 1e 13 da 1e 11 38 88 c5 65

Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

convert mmddyy date format to ccyyddd format??

hi, for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format. i checked the datecalc and other scripts but couldnt modify them to cater to my need:(... The datecalc gives an output which i believe is the total days till that date, but i want to convert it... (2 Replies)
Discussion started by: Bhups
2 Replies

2. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

3. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

4. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

5. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

6. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

7. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

8. UNIX for Dummies Questions & Answers

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (1 Reply)
Discussion started by: Samtel
1 Replies

9. Shell Programming and Scripting

Convert UNIX file format to PC format

Hi All, Is there any way to convert a file which is in UNIX format to a PC format.... Flip command can be used , apart form this command can we have any other way.... like usinf "awk" etc ..... main purpose of not using flip is that my Kshell doesnot support this comamnd.... (2 Replies)
Discussion started by: Samtel
2 Replies

10. Shell Programming and Scripting

perl module to convert xlsx format to xls format

Hi Folks, I have written a perl script that reads data from excel sheet(.xls) using Spreadsheet::ParseExcel module. But the problem is this module doesn't work for excel sheets with extension .xlsx. I have gone through Spreadsheet::XLSX module with which we can read from .xlsx file directly.... (1 Reply)
Discussion started by: giridhar276
1 Replies
TEXT2PCAP(1)						  The Wireshark Network Analyzer					      TEXT2PCAP(1)

NAME
text2pcap - Generate a capture file from an ASCII hexdump of packets SYNOPSIS
text2pcap [ -a ] [ -d ] [ -D ] [ -e <l3pid> ] [ -h ] [ -i <proto> ] [ -l <typenum> ] [ -n ] [ -m <max-packet> ] [ -o hex|oct|dec ] [ -q ] [ -s <srcport>,<destport>,<tag> ] [ -S <srcport>,<destport>,<ppi> ] [ -t <timefmt> ] [ -T <srcport>,<destport> ] [ -u <srcport>,<destport> ] <infile>|- <outfile>|- DESCRIPTION
Text2pcap is a program that reads in an ASCII hex dump and writes the data described into a pcap capture file. text2pcap can read hexdumps with multiple packets in them, and build a capture file of multiple packets. text2pcap is also capable of generating dummy Ethernet, IP and UDP, TCP, or SCTP headers, in order to build fully processable packet dumps from hexdumps of application-level data only. Text2pcap understands a hexdump of the form generated by od -Ax -tx1 -v. In other words, each byte is individually displayed and surrounded with a space. Each line begins with an offset describing the position in the file. 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 e0 1e a7 05 6f 00 10 ........ 000008 5a a0 b9 12 08 00 46 00 ........ 000010 03 68 00 00 00 00 0a 2e ........ 000018 ee 33 0f 19 08 7f 0f 19 ........ 000020 03 80 94 04 00 00 10 01 ........ 000028 16 a2 0a 00 03 50 00 0c ........ 000030 01 01 0f 19 03 80 11 01 ........ 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. OPTIONS
-a Enables ASCII text dump identification. It allows to identify the start of the ASCII text dump and not include it in the packet even if it looks like HEX. NOTE: Do not enable it if the input file does not contain the ASCII text dump. -d Displays debugging information during the process. Can be used multiple times to generate more debugging information. -D The text before the packet starts either with an I or O indicating that the packet is inbound or outbound. This is only stored if the output format is PCAP-NG. -e <l3pid> Include a dummy Ethernet header before each packet. Specify the L3PID for the Ethernet header in hex. Use this option if your dump has Layer 3 header and payload (e.g. IP header), but no Layer 2 encapsulation. Example: -e 0x806 to specify an ARP packet. For IP packets, instead of generating a fake Ethernet header you can also use -l 101 to indicate a raw IP packet to Wireshark. Note that -l 101 does not work for any non-IP Layer 3 packet (e.g. ARP), whereas generating a dummy Ethernet header with -e works for any sort of L3 packet. -h Displays a help message. -i <proto> Include dummy IP headers before each packet. Specify the IP protocol for the packet in decimal. Use this option if your dump is the payload of an IP packet (i.e. has complete L4 information) but does not have an IP header with each packet. Note that an appropriate Ethernet header is automatically included with each packet as well. Example: -i 46 to specify an RSVP packet (IP protocol 46). -l Specify the link-layer header type of this packet. Default is Ethernet (1). See <http://www.tcpdump.org/linktypes.html> for the complete list of possible encapsulations. Note that this option should be used if your dump is a complete hex dump of an encapsulated packet and you wish to specify the exact type of encapsulation. Example: -l 7 for ARCNet packets encapsulated BSD-style. -m <max-packet> Set the maximum packet length, default is 65535. Useful for testing various packet boundaries when only an application level datastream is available. Example: od -Ax -tx1 -v stream | text2pcap -m1460 -T1234,1234 - stream.pcap will convert from plain datastream format to a sequence of Ethernet TCP packets. -n Write PCAP-NG file instead of a PCAP. -o hex|oct|dec Specify the radix for the offsets (hex, octal or decimal). Defaults to hex. This corresponds to the "-A" option for od. -q Be completely quiet during the process. -s <srcport>,<destport>,<tag> Include dummy SCTP headers before each packet. Specify, in decimal, the source and destination SCTP ports, and verification tag, for the packet. Use this option if your dump is the SCTP payload of a packet but does not include any SCTP, IP or Ethernet headers. Note that appropriate Ethernet and IP headers are automatically also included with each packet. A CRC32C checksum will be put into the SCTP header. -S <srcport>,<destport>,<ppi> Include dummy SCTP headers before each packet. Specify, in decimal, the source and destination SCTP ports, and a verification tag of 0, for the packet, and prepend a dummy SCTP DATA chunk header with a payload protocol identifier if ppi. Use this option if your dump is the SCTP payload of a packet but does not include any SCTP, IP or Ethernet headers. Note that appropriate Ethernet and IP headers are automatically included with each packet. A CRC32C checksum will be put into the SCTP header. -t <timefmt> Treats the text before the packet as a date/time code; timefmt is a format string of the sort supported by strptime(3). Example: The time "10:15:14.5476" has the format code "%H:%M:%S." NOTE: The subsecond component delimiter must be specified (.) but no pattern is required; the remaining number is assumed to be fractions of a second. NOTE: Date/time fields from the current date/time are used as the default for unspecified fields. -T <srcport>,<destport> Include dummy TCP headers before each packet. Specify the source and destination TCP ports for the packet in decimal. Use this option if your dump is the TCP payload of a packet but does not include any TCP, IP or Ethernet headers. Note that appropriate Ethernet and IP headers are automatically also included with each packet. Sequence numbers will start at 0. -u <srcport>,<destport> Include dummy UDP headers before each packet. Specify the source and destination UDP ports for the packet in decimal. Use this option if your dump is the UDP payload of a packet but does not include any UDP, IP or Ethernet headers. Note that appropriate Ethernet and IP headers are automatically also included with each packet. Example: -u1000,69 to make the packets look like TFTP/UDP packets. SEE ALSO
od(1), pcap(3), wireshark(1), tshark(1), dumpcap(1), mergecap(1), editcap(1), strptime(3), pcap-filter(7) or tcpdump(8) NOTES
Text2pcap is part of the Wireshark distribution. The latest version of Wireshark can be found at <http://www.wireshark.org>. AUTHORS
Ashok Narayanan <ashokn[AT]cisco.com> 1.10.3 2013-07-29 TEXT2PCAP(1)
All times are GMT -4. The time now is 01:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy