Netcat: Is there a way to send a continuous stream from command output to a remote listener

I am using netcat for unix.

when i run python script.py &> logfile.txt , it is fixed continuously.

To replicate this remotely, I tried nc -l -p 8011 on the listener (client) and for the sender (host or server) the following:

  • python script.py &> nc 127.0.0.1 8011
  • python script.py > nc 127.0.0.1 8011
  • nc 127.0.0.1 8011 < python script.py

But nothing works. Please, help.

+4
source share
2 answers

That's what you need?

Recipient:

 nc -l 8011 >logfile.txt 

Sender:

 python script.py 2>&1 | nc 127.0.0.1 8011 

Be sure to run the receiver code first.


EDIT . If you do not know that there are many different versions of netcat ; they all take slightly different arguments (e.g. nc.traditional on Debian wants nc -l -p 1234 listen on port 1234, while BSD nc (e.g. OS X) just wants nc -l 1234 and ncat can cause an interesting error if you do not use the -4 flag if your host does not support IPv6) - read the manual pages to find out which combination of parameters you really want.

+2
source

Great answer with one small modification: adding -p to the "port"

Recipient:

 nc -l -p 8011 >logfile.txt 

I pulled out the nc help file (nc -h) using your suggestion

Sender:

 nc -h 2>&1 | nc 127.0.0.1 8011 

I tried

 nc -h > logfile.txt nc -h >> logfile.txt 

which never worked.

I am running netcat for Windows 7 in 2 cmd.exe

Thanks again

+1
source

All Articles