Search code examples
linuxnetcat

Receiving bytes with netcat


I have a script that sends data over a TCP connection with netcat which is working well.

What I would like to do is receive the data sent back by the server, and on a specific response, do an action.

The problem I have is that I don't know how to extract the full data package sent to me.

For example, the server sends me the following data (caught on Wireshark):

02 01 00 00 00 00 00 00 08 00   ..........
31 00 03                        1..

but the output from netcat only prints '1' (0x31 in ASCII).

I would like to be able to print the full data packet 02 01 ... 00 03. Is that possible?

Another problem is that each received data packet replaces the previous one. So even though I only currently can print the "1" from the received data, the next data will overwrite it in the output file.

Is there any way to add a new line to the output file after printing each received data packet?

I hope I have been clear enough. Any help would be greatly appreciated.


Solution

  • I would like to be able to print the full data packet 02 01 ... 00 03. Is that possible ?

    For this I used the netcat -o file option. This dumps all traffic into the specified output file.