Is there a way to send a continuous stream from a

2019-06-28 00:44发布

I'm using the netcat for unix.

when I run python script.py &> logfile.txt , it gets captured continuously.

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

  1. python script.py &> nc 127.0.0.1 8011
  2. python script.py > nc 127.0.0.1 8011
  3. nc 127.0.0.1 8011 < python script.py

But nothing seems to work. Please help.

2条回答
老娘就宠你
2楼-- · 2019-06-28 01:37

Is this what you're after?

Receiver:

nc -l 8011 >logfile.txt

Sender:

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

Make sure to run the receiver code first.


EDIT: In case you're not aware there's a lot of different versions of netcat; they all accept slightly different arguments (e.g. nc.traditional on Debian wants nc -l -p 1234 to listen on port 1234, whereas BSD nc (e.g. OS X) just wants nc -l 1234 and ncat may throw an interesting error unless you use the -4 flag if your host doesn't support IPv6) - read the man pages to find out what combination of options you actually want.

查看更多
三岁会撩人
3楼-- · 2019-06-28 01:43

Perfect answer, with one slight modification: adding -p for "port"

Receiver:

nc -l -p 8011 >logfile.txt

I pulled in 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'm running netcat for Windows 7 in 2 cmd.exe's

Thanks, again

查看更多
登录 后发表回答