Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send String over netcat connection

Tags:

python

netcat

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

like image 418
Crizly Avatar asked May 23 '16 10:05

Crizly


3 Answers

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>
like image 169
cb0 Avatar answered Nov 09 '22 19:11

cb0


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.

like image 20
Manjunath Raddi Avatar answered Nov 09 '22 20:11

Manjunath Raddi


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.

like image 3
geekypandey Avatar answered Nov 09 '22 19:11

geekypandey