Multiple input feeds to netcat

2.6k views Asked by At

This is related to passing input through stdin to a binary running on a port. I am able to run the binary using netcat as follows:

nc $server $port

Now to pass a single line, I can get the following working:

python -c 'print "AAAA"' | nc $server $port

However, I am not able to figure out a way to write to stdin twice.

My program has a flow something like below:

The first feed depends on some response from the server.

line 5: read(stdin,&buffer,20); // This entry is based on some question from the server and need to be determined dynamically

The second feed needs to passed as a python output as it needs to contain hex characters as well.

line 8: read(stdin,&buffer2,20); // This feed is static.

Any help here will be highly appreciated.

Thanks!

1

There are 1 answers

1
nickgrim On

Not entirely sure I understand the problem, but you can run multiple commands in a subshell and pipe the output of all of them to another process:

$ (python -c 'print "AAAA"'; python -c 'print "BBBB"') | nc $server $port