Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending a hex string to a remote via netcat

Tags:

netcat

I've got some binary commands (which I'm representing as hex) that I need to send to a remote device (it's an embedded data collection device) and observe the reply.

It's easy to connect to it with netcat

nc -v 192.168.200.34 19000

and it sits there happy as a clam.

The hex string I need to type in terminal and then send is something like:

02:45:31:38:03:34:43:0d:0a

Where 02 is STX, 03 is ETX and so on.

But when I type this into my netcat window (with or without spaces , with or without the colons) netcat transmits it as ascii.

All the literature is happy to tell me how to capture a hexdump from the remote device, but not how to transmit binary/hex data to the remote device.

Is this an easy thing to do, or am I missing something?

like image 417
fl4r3 Avatar asked May 11 '17 15:05

fl4r3


1 Answers

You can do it with command: echo -n -e "\x02\x45\x31\x38\x03\x34\x43\x0d\x0a" | nc [-u] <-ip-addr-> <-port-no->

  • The -n supresses outputting the trailing newline.
  • The -e enables the interpretation of backslash escapes -> allowing us to send hex codes.
  • 'x' before each character specifies that the byte is in hexadecimal form.
  • -u switch to UDP traffic (optional)
like image 107
rahul1205 Avatar answered Sep 22 '22 21:09

rahul1205