Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send one byte symbol to server socket with netcat?

Tags:

sockets

netcat

There's already a working server service via socket, and I would like to test it via netcat. I'm using Mac OS X Lion. Currently, I'm able to connect to server via port, to send packet, but the packet contains wrong value. Here are the details:

I need to send 'm' symbol to the server and the server will return 00000000, a zero byte as a response. Server guy told me, server receives 'A0' when I'm sending 'm', and server receives '313039A' when I'm sending '109'. How to define sending format or something, I just need to send 'm' (01101101)?

like image 235
Centurion Avatar asked Feb 07 '12 14:02

Centurion


People also ask

How do you send bytes in North Carolina?

To send bytes, you just type the ASCII character to get that byte. If the byte you need to send is less that the type-able characters, you hold Ctrl down to subtract 64 off of the ASCII value. Run: telnet 127.0. 0.1 1234 to connect, then press Ctrl+D to send 0x04 (since D is 0x68).

How do you specify a port to listen on netcat?

On one machine, you can tell netcat to listen to a specific port for connections. We can do this by providing the -l parameter and choosing a port: netcat -l 4444.


1 Answers

You can send just "m" with

echo -n 'm' | nc <server> <port>

You can easily check what you're sending on your local machine:

# in one Terminal start the listener:
$ nc -l 1234 | hexdump -C
00000000  6d                                                |m|
00000001

# in other Terminal send the packet:
$ echo -n 'm' | nc 127.0.0.1 1234

nc will happily send/receive NUL bytes - there is no problem with that:

# sending side
$ echo -n X | tr X '\000' | nc 127.0.0.1 1234

# receiving side
$ nc -l 1234 | hexdump -C
00000000  00                                                |.|
00000001
like image 90
Simon Urbanek Avatar answered Oct 18 '22 09:10

Simon Urbanek