Sponsored Content
Top Forums Shell Programming and Scripting [PERL] Convert TCP response to HEX Post 302981294 by Lord Spectre on Friday 9th of September 2016 02:43:43 PM
Old 09-09-2016
[PERL] Convert TCP response to HEX

Dear community, I'm going crazy to convert TCP response to HEX using perl. I have a simple connection request where I send data, something like:

Code:
use strict;
use IO::Socket;
my $sock;
$sock = new IO::Socket::INET(
                  PeerAddr => '192.168.10.7',
                  PeerPort => 8000,
                  Proto    => 'tcp');
$sock or die "no socket :$!";

Then I send SMPP data:
Code:
# send bind request
$_ = "0000001C0000000900000000000000014C4131303000000034000000";
my @hexdata = /(\w{2})/g;
my $str = join('', map { chr(hex $_) } @hexdata);
print $sock $str;

This works perfect, server receive the SMPP string and reply with data. At this point I intercept the response:
Code:
my $response = "";
$sock->recv($response, 1024);
print "Received response: $response\n";

The problem there is that I receive ascii data like:
Code:
Received response: €    ABC35SMPP4

What I need is convert what I receive from server (bytes??) in hex:
Code:
00 00 00 20 80 00 00 04 00 00 00 00 00 00 00 01 41 41 52 31 36 30 39 30 39 31 38 35 33 30 35 00

How can I do that?

Thank you
Lucas

---------- Post updated at 01:43 PM ---------- Previous update was at 11:58 AM ----------

Done :-)
It was so simple!!!!

Code:
  my $data;
  $sock->recv($data, 512);
  $data = unpack( 'h*sx', $data );

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

convert hex to ascii text

Is there a command to convert hex characters into their respective ascii values? (5 Replies)
Discussion started by: dangral
5 Replies

2. Programming

to convert int to hex

Hi, Can you help me in converting int value to hex in a single command. Thanks (8 Replies)
Discussion started by: naan
8 Replies

3. Shell Programming and Scripting

How to Convert Hex value to Dec ?

Hi All, I want to convert below Hex value to Dec value in each column .How to do it ? This data is in a 1 file. 4e20 0475 2710 010f 7530 69a2 7530 7e2f 4e20 02dd 7530 6299 4e20 0c0a 7530 69a2 4e20 0a0b 2710 0048 7530 7955 4e20 0d23 7530 622d 7530 9121 2710 001f 7530 7d3f (6 Replies)
Discussion started by: Nayanajith
6 Replies

4. Programming

Convert HEX to EBCDIC IN C

i want to convert Hex value To EBCDIC value. i tried to convert hex to ascii and then to ebcdic but it doesn't give desired results . it doesn't give corresponding ebcdic value instead it gives some junk values. e.g; Hex EBCDIC ----------------- 81 a 82 b 83 c 84 d 85 e 86 f 87... (6 Replies)
Discussion started by: junaid.nehvi
6 Replies

5. Shell Programming and Scripting

How to convert hex numbers to decimal ?

Hi, please tell me how to convert hex number to decimal 000000E7 000000000002640D 0000000000025B16 and seconds to minutes, hours, days, months, years bytes to kbytes, mbytes , gbytes read the following examples while read a b do printf "%5d %5d\n" "0x$a" "0x$b" done < "$FILE"... (15 Replies)
Discussion started by: jack2
15 Replies

6. Shell Programming and Scripting

Convert hex to decimal or reverse is better?

Please Help Me! about the problem down under. I have 2 files with nearly the same characteristics, I have to convert one to the other format or the other format to one's format. I want to write it with awk. The first file contain lines like this: 300000001#A#Y#Y#Y#Y The other file contain... (4 Replies)
Discussion started by: Axel82
4 Replies

7. Shell Programming and Scripting

Convert Hex - KSH

Hello, I woild like to convert hex on KSH not BASH: I tried to use: tmp=31 printf "\x"${tmp}"" it works on bash - Output is '1' but not on ksh. please advice on the right syntax. Thanks. (4 Replies)
Discussion started by: LiorAmitai
4 Replies

8. Shell Programming and Scripting

Convert to Hex in perl

Hi, i want to convert number 5860533159 to hexadecimal. i need to use perl. i used $foo = 5860533159; $hexval3 = sprintf("%#x", $foo); i am getting value as 0xffffffff. i need to get value as 0x15D50A3A7. when i converted using google calculator, i got the correct value, expected... (9 Replies)
Discussion started by: asak
9 Replies

9. Shell Programming and Scripting

Convert hex to decimal

can someone help me in converting hex streams to decimal values using perl script Hex value: $my_hex_stream="0c07ac14001676"; Every hex value in the above stream should be converted in to decimal and separated by comma. The output should be: 12,07,172,20,00,22,118 (2 Replies)
Discussion started by: Arun_Linux
2 Replies

10. UNIX for Beginners Questions & Answers

How to convert dec to hex in python?

When I try to convert big numbers I get extra numbers at the end that doesn't move plus an L character too. How to remove the 4 extra characters at the end 000L? 8b8dbbc584d9c000L 8b8dc4ddd34c6000L 8b8dcdf621bf0000L 8b8dd70e7031a000L 8b8de026bea44000L #!/usr/bin/python ... (9 Replies)
Discussion started by: bigvito19
9 Replies
TCPCLI(1)							  BP executables							 TCPCLI(1)

NAME
tcpcli - DTN TCPCL-compliant convergence layer input task SYNOPSIS
tcpcli local_hostname[:local_port_nbr] DESCRIPTION
tcpcli is a background "daemon" task comprising 1 + N threads: one that handles TCP connections from remote tcpclo tasks, spawning sockets for data reception from those tasks, plus one input thread for each spawned socket to handle data reception over that socket. The connection thread simply accepts connections on a TCP socket bound to local_hostname and local_port_nbr and spawns reception threads. The default value for local_port_nbr, if omitted, is 4556. Each time a connection is established, the end-points will first exchange contact headers, because connection parameters need to be negotiated. tcpcli records the acknowledgement flags, reactive fragmentation flag and negative acknowledgements flag in the contact header it receives from its peer tcpclo task. Each reception thread receives bundles over the associated connected socket. Each bundle received on the connection is preceded by message type, fragmentation flags, and size represented as an SDNV. The received bundles are passed to the bundle protocol agent on the local ION node. tcpcli is spawned automatically by bpadmin in response to the 's' (START) command that starts operation of the Bundle Protocol; the text of the command that is used to spawn the task must be provided at the time the "tcp" convergence layer protocol is added to the BP database. The convergence layer input task is terminated by bpadmin in response to an 'x' (STOP) command. tcpcli can also be spawned and terminated in response to START and STOP commands that pertain specifically to the TCP convergence layer protocol. EXIT STATUS
0 tcpcli terminated normally, for reasons noted in the ion.log file. If this termination was not commanded, investigate and solve the problem identified in the log file and use bpadmin to restart tcpcli. 1 tcpcli terminated abnormally, for reasons noted in the ion.log file. Investigate and solve the problem identified in the log file, then use bpadmin to restart tcpcli. FILES
No configuration files are needed. ENVIRONMENT
No environment variables apply. DIAGNOSTICS
The following diagnostics may be issued to the ion.log log file: tcpcli can't attach to BP. bpadmin has not yet initialized Bundle Protocol operations. No such tcp duct. No TCP induct matching local_hostname and local_port_nbr has been added to the BP database. Use bpadmin to stop the TCP convergence- layer protocol, add the induct, and then restart the TCP protocol. CLI task is already started for this duct. Redundant initiation of tcpcli. Can't get IP address for host Operating system error. Check errtext, correct problem, and restart TCP. Can't open TCP socket Operating system error. Check errtext, correct problem, and restart TCP. Can't initialize socket Operating system error. Check errtext, correct problem, and restart TCP. tcpcli can't create access thread Operating system error. Check errtext, correct problem, and restart TCP. BUGS
Report bugs to <ion-bugs@korgano.eecs.ohiou.edu> SEE ALSO
bpadmin(1), bprc(5), tcpclo(1) perl v5.14.2 2012-05-25 TCPCLI(1)
All times are GMT -4. The time now is 06:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy