Crizly Crizly - 1 year ago 125
Python Question

Send String over netcat connection

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)?

cb0 cb0
Answer Source

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>