Terminal command to send data (plain text string) to a port at a remote computer

2

1

I am trying to send data (plain text string) to a port at a remote computer using terminal utility. The string would be used to trigger something on the remote computer running a program that would listen to that specific port.

I used netcat command and tried a few combination of the following but can't seem to get the parameter right. Can someone point me out where am I doing wrong?

eddy-2:Desktop eddy$ nc IPADDRESS PORT >  woc.txt
eddy-2:Desktop eddy$ nc IPADDRESS PORT <  woc.txt

P.S: woc.txt contains plain text string of the said command.

Edit: I am trying to send a string from OSX to Windows XP where the specific port is open by default.

Scott

Posted 2010-12-23T02:49:57.550

Reputation: 147

Answers

4

Use netcat as so:

Server: cat woc.txt | nc -l -p PORT

Client: nc HOST PORT > woc.txt


Thanks to garyjohn for the above modification.

new123456

Posted 2010-12-23T02:49:57.550

Reputation: 3 707

Added an edit to my post above. I am trying to send a string from OSX to Windows XP where the specific port is open by default. Must cat and netcat be running at the same time for this thing to work.

Note: I tried quite a number of other combination from man page but felt that I was missing something so I asked. – Scott – 2010-12-23T02:57:52.783

@Eddy - No. Run the server first (it will appear to hang while waiting for a client), client second. – new123456 – 2010-12-23T03:01:39.737

nc IPADDRESS PORT < woc.txt should work fine. What do have listening on the server's PORT? – garyjohn – 2010-12-23T06:48:09.673

1@Eddy: Your server command is missing a -p. It should be nc -l -p PORT < woc.txt. Also, I understood new123456 to want to send the contents of woc.txt to the server. – garyjohn – 2010-12-23T06:53:20.340

@garyjohn - Correct. Quoting Eddy: woc.txt contains plaintext string of the said command – new123456 – 2010-12-23T14:29:44.437