【问题标题】:unix netcat utility on linux, checking if connection was madelinux上的unix netcat实用程序,检查是否建立了连接
【发布时间】:2012-09-10 15:42:58
【问题描述】:

我在 linux 上使用 netcat 实用程序从 Windows 机器上的程序接收输出。我的问题是windows机器上的程序并不总是给出输出。

如何检查是否已与 netcat 建立连接?

到目前为止我正在做的是“nc -l -v 9103 > output”然后我检查输出的大小,这带来的问题是netcat仅在达到一定缓冲区大小或遇到新行字符后才写入文件,因此在某些情况下,即使已建立连接,文件大小也会被检测为零。

如何检查是否有人与 netcat 建立了连接。

我尝试过使用

nc -l -v -e someprog.exe 9103 > output

但我的 netcat 似乎不支持这个

以下是我的选择

    $ nc -h
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]
          [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]
          [-x proxy_address[:port]] [hostname] [port[s]]
        Command Summary:
                -4              Use IPv4
                -6              Use IPv6
                -D              Enable the debug socket option
                -d              Detach from stdin
                -h              This help text
                -i secs         Delay interval for lines sent, ports scanned
                -k              Keep inbound sockets open for multiple connects
                -l              Listen mode, for inbound connects
                -n              Suppress name/port resolutions
                -p port         Specify local port for remote connects
                -r              Randomize remote ports
                -s addr         Local source address
                -T ToS          Set IP Type of Service
                -C              Send CRLF as line-ending
                -t              Answer TELNET negotiation
                -U              Use UNIX domain socket
                -u              UDP mode
                -v              Verbose
                -w secs         Timeout for connects and final net reads
                -X proto        Proxy protocol: "4", "5" (SOCKS) or "connect"
                -x addr[:port]  Specify proxy address and port
                -z              Zero-I/O mode [used for scanning]
        Port numbers can be individual or ranges: lo-hi [inclusive]

【问题讨论】:

    标签: linux sockets netcat


    【解决方案1】:

    详细模式将写入到标准错误的连接,您可以将标准错误重定向到一个文件,详细日志有类似 从 [xxxx] 连接到 [xxx]

    试试

    nc -l -v -p 9103 -k 1> output 2>connect.log
    

    并监控 connect.log 的连接性

    如果您不使用 -k ,netcat 在第一次连接后退出。

    【讨论】:

      【解决方案2】:

      如果您可以升级您的 netcat 副本:现代版本(一个是 1.10)可以选择在连接时执行程序(或 shell 命令)。否则,您可以使 netcat 认为它在终端中运行(以禁用标准输出的缓冲),例如使用 script(它只是将所有内容保存在给定文件中的 stdin/stdout/stderr 上)。或者使用screen 和tmux 的日志记录功能。

      【讨论】:

      • 你能详细说明我会怎么做吗?
      • 哪个?升级netcat,使用script,screen,还是tmux?
      猜你喜欢
      • 2013-03-11
      • 1970-01-01
      • 2012-06-11
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多