有没有一种方法可以将命令输出中的连续流发送到远程侦听器

编程入门 行业动态 更新时间:2024-10-08 18:37:58
本文介绍了有没有一种方法可以将命令输出中的连续流发送到远程侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将netcat用于UNIX.

I'm using the netcat for unix.

当我运行 python script.py&logfile.txt ,它会被连续捕获.

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

要远程复制此文件,我在侦听器(客户端)上尝试了 nc -l -p 8011 ,在发送方(主机或服务器)上尝试了以下操作:

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

  • 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 seems to work. Please help.

    推荐答案

    这是您要的吗?

    接收器:

    nc -l 8011 >logfile.txt

    发件人:

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

    确保首先运行接收器代码.

    Make sure to run the receiver code first.

    编辑:如果您不知道有很多不同版本的netcat ;它们都接受略有不同的参数(例如Debian上的 nc.traditional 希望 nc -l -p 1234 监听端口1234,而BSD nc (例如OS X)只希望 nc -l 1234 和 ncat 可能引发一个有趣的错误,除非您的主机没有使用 -4 标志'不支持IPv6)-请阅读手册页,以了解您真正想要的选项组合.

    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.

    更多推荐

    有没有一种方法可以将命令输出中的连续流发送到远程侦听器

    本文发布于:2023-11-25 21:05:35,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1631344.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:连续流   侦听器   发送到   命令   方法

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!