I have two virtual machines open, one is listening on the connection, the other connects with nc <ip> <port>
from a python subprocess call. I want to send just 1 line of text over the connection then close it. I know how to send a file cat cat <file> | nc <ip> <port>
but how can I just send a line of text in the nc command (without using files)?
Try this:
echo -n 'Line of text' | nc <ip> <port>
You can also use temp file syntax:
cat <(echo "Line of test") | nc <ip> <port>
Create file test.txt
, content of file is 1
netcat [ip-address] [port] <test.txt
At destination you must have something to listen to this.
The temp file syntax shown by @cb0 could also be used as:
nc <ip> <port> <( echo "Line of text" )
without having to use cat
command. This would create a temporary file with the content "Line of text" and then redirect it to the netcat command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With