为什么“nc -l xxxx”没有打开端口?

为什么“nc -l xxxx”没有打开端口?

我尝试让 netcat 监听端口 4444,但似乎不起作用。我使用 nmap 检查端口是否打开,但它没有检测到,我不明白为什么。我尝试了各种端口,但都没有成功。

这是我的终端的副本,以便您可以看到我正在做什么以及我尝试了什么:

#iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination


# nmap localhost -p 4444

Starting Nmap 5.61TEST4 ( http://nmap.org ) at 2012-07-31 16:37 BST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00019s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT     STATE  SERVICE
4444/tcp closed krb524

Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds


# nc -l 4444 &
[1] 1951


# nmap  localhost -p 1-65535

Starting Nmap 5.61TEST4 ( http://nmap.org ) at 2012-07-31 16:42 BST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0000070s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 65532 closed ports
PORT      STATE SERVICE
22/tcp    open  ssh
7337/tcp  open  unknown
33507/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 1.37 seconds


# ps -e | grep nc
   12 ?        00:00:00 sync_supers
 1156 tty1     00:00:00 ck-launch-sessi
 1232 tty1     00:00:00 dbus-launch
 1274 ?        00:00:00 klauncher
 1951 pts/2    00:00:00 nc

答案1

我运行了详细模式-v并得到了一条线索:

4444: inverse host lookup failed: Unknown server error : Connection timed out`
listening on [any] 41579 ...`

-p所以我尝试像这样指定一个端口nc -lvp 4444并且它有效:

listening on [any] 4444 ...

显然我需要与这个版本的 nc-p一起使用。-l

如果有人能告诉我为什么会有这种差异,我会非常高兴。我运行的是旧版本吗?(-h报告v1.10-38

相关内容