Sending a hex string to a remote via netcat

让人想犯罪 __ 提交于 2021-01-22 03:59:21

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/43919867/sending-a-hex-string-to-a-remote-via-netcat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!