32

I am trying to use netcat to send a simple message over TCP, e.g. I want to send the digit 1.

So I understood that I write the following in the terminal, after installing netcat

netcat [ip-address] [port]

But how do I specify the message to be sent? i.e. where to I write "1" ?

  • Not sure why this is specific to askubuntu. I think this should be moved to a more relevant location in StackExchange. – jamescampbell Jul 27 '18 at 23:44
38

Create file something.txt, content of file is 1

netcat [ip-address] [port] <something.txt

At destination you must have something to listen to this.

or

Server:

netcat -l -p [port]

to listen to the connection

Client:

netcat [server-ip-address] [port]

After connection is establish on cilent simple type 1 and hit enter

  • Submitted an edit changing the useless cat command to redirection to echo. I use this method to send string data to remote machines that are operating as one for greater bash multi-tasking. – Yokai Nov 14 '17 at 8:27
  • +1 for the server tip! That's very cool, thanx! – j.c Feb 26 '18 at 14:31
  • thnks, this is working for me – Buddhika Alwis Jul 11 '18 at 4:52
13

I use:

echo text | netcat host port

So you would just need to run this:

echo 1 | netcat localhost 12345
  • 2
    or netcat <host> <port> <<< 1 – Jon Carlson Aug 23 '18 at 18:24

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.