Mac OS X 10.8.4上的nc(netcat)被卡住 [英] nc (netcat) on Mac OS X 10.8.4 gets stuck

查看:193
本文介绍了Mac OS X 10.8.4上的nc(netcat)被卡住的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OS X上使用nc实用程序时遇到了一个小问题,我经常将它用作快速而又肮脏的解决方案,以检查端口是否打开以及守护程序正在运行的版本.

I encountered a little issue while using the nc utility on Mac OS X, a utility i often use as a quick and dirty solution to check if a port is open and what version the daemon is running.

前几天,我们部署了一组新计算机,我想验证它们正在运行的sshd版本,而不必离开我的椅子.

We deployed a new set of computers the other day and i wanted to verify what version of sshd they were running, without having to leave my chair.

这是我运行的命令和结果输出:

This is the command i ran and the resulting output:

$ for i in {183..200}; do echo "hello" | nc -n -w 2 -v 10.120.113.$i 22; done
Connection to 10.120.113.183 22 port [tcp/*] succeeded!
SSH-2.0-OpenSSH_5.9
Protocol mismatch.
nc: connect to 10.120.113.184 port 22 (tcp) failed: Connection refused
^C
$

它在183上找到第一台计算机并返回守护程序版本,它看起来不像sshd在184上运行,但是当它达到185时,它就停止了,我必须用ctrl + c杀死它.

It finds the first machine on 183 and returns the daemon version, it dont look like the sshd is running on 184, but when it hits 185 it simply stops and i have to kill it with ctrl+c.

据我所知,nc的手册页应该在使用'-w'开关时超时,但事实并非如此.来自多台计算机的相同问题.

As i have understood the man page for nc it should time out when using the '-w' switch, but it don't. Its the same issue from multiple machines.

我只是误解了手册页吗? 如果没有收到任何回应,还有其他方法可以使X秒后nc超时吗? 使用Mac OS X中的内置工具还有其他方法吗?

Is this simply the case of me misunderstanding the man page? Is there any other way to make nc time out after X seconds if don´t receive any response? Is there any other way to do this using the builtin tools in Mac OS X?

我还尝试了仅使用'-z'开关运行nc的结果. 这些机器已放置在我们的产品中,因此我不允许安装任何第三方应用程序,例如nmap.

I´ve also tried running nc with only the '-z' switch with the same results. The machines are placed in our production so i´m not allowed to install any 3rd party applications like nmap.

Platform: Mac OS X 10.8.4
Executable: /usr/bin/nc

很抱歉,如果这个问题已经回答,我进行了搜索,但找不到任何解决方案.

Sorry if this question has been answered, i searched but could not find any solution to this.

推荐答案

我相信您正在寻找-G选项.在手册页中:

I believe you are looking for the -G option. From the man pages:

-G超时 TCP连接超时(以秒为单位).

-G conntimeout TCP connection timeout in seconds.

-w用于设置连接后 后的超时. -G选项用于设置连接之前 的超时.这应该给你你想要的东西

-w is used to set the timeout after connection. -G option is used to set the timeout before connection. This should give you what you want

nc -n -G 2 -v xxx.xxx.xxx.xxx 22

这篇关于Mac OS X 10.8.4上的nc(netcat)被卡住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆