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

9,627

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.

Share:
9,627

Related videos on Youtube

Scott
Author by

Scott

Updated on September 17, 2022

Comments

  • Scott
    Scott over 1 year

    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
    Scott over 13 years
    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.
  • new123456
    new123456 over 13 years
    @Eddy - No. Run the server first (it will appear to hang while waiting for a client), client second.
  • garyjohn
    garyjohn over 13 years
    nc IPADDRESS PORT < woc.txt should work fine. What do have listening on the server's PORT?
  • garyjohn
    garyjohn over 13 years
    @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.
  • new123456
    new123456 over 13 years
    @garyjohn - Correct. Quoting Eddy: woc.txt contains plaintext string of the said command