我如何在自己的服务器上找出哪些端口是开放的?如何使用 nc 命令进行端口扫描来替换 Linux 或类 Unix 中的 nmap 命令?
nmap (“Network Mapper”)是一个用于网络探测和安全审核的开源工具。如果 nmap 没有安装或者你不希望使用 nmap,那你可以用 netcat/nc 命令进行端口扫描。它对于查看目标计算机上哪些端口是开放的或者运行着服务是非常有用的。你也可以使用 nmap 命令进行端口扫描 。
如果未安装 nmap,试试 nc/netcat 命令,如下所示。-z 参数用来告诉 nc 报告开放的端口,而不是启动连接。在 nc 命令中使用 -z 参数时,你需要在主机名/ip 后面限定端口的范围和加速其运行:
### 语法 ###### nc -z -v {host-name-here} {port-range-here}nc -z -v host-name-here sshnc -z -v host-name-here 22nc -w 1 -z -v server-name-here port-Number-her### 扫描 1 to 1023 端口 ###nc -zv vip-1.vsnl.nixcraft.in 1-1023输出示例:
Connection to localhost 25 port [tcp/smtp] succeeded!Connection to vip-1.vsnl.nixcraft.in 25 port [tcp/smtp] succeeded!Connection to vip-1.vsnl.nixcraft.in 80 port [tcp/http] succeeded!Connection to vip-1.vsnl.nixcraft.in 143 port [tcp/imap] succeeded!Connection to vip-1.vsnl.nixcraft.in 199 port [tcp/smux] succeeded!Connection to vip-1.vsnl.nixcraft.in 783 port [tcp/*] succeeded!Connection to vip-1.vsnl.nixcraft.in 904 port [tcp/vmware-authd] succeeded!Connection to vip-1.vsnl.nixcraft.in 993 port [tcp/imaps] succeeded!你也可以扫描单个端口:
nc -zv v.txvip1 443nc -zv v.txvip1 80nc -zv v.txvip1 22nc -zv v.txvip1 21nc -zv v.txvip1 smtpnc -zvn v.txvip1 ftp### 使用1秒的超时值来更快的扫描 ###netcat -v -z -n -w 1 v.txvip1 1-1023输出示例:
图01:Linux/Unix:使用 Netcat 来测试 TCP 和 UDP 与服务器建立连接
-z : 端口扫描模式即零 I/O 模式。-v : 显示详细信息 [使用 -vv 来输出更详细的信息]。-n : 使用纯数字 IP 地址,即不用 DNS 来解析 IP 地址。-w 1 : 设置超时值设置为1。更多例子:
$ netcat -z -vv www.cyberciti.biz httpwww.cyberciti.biz [75.126.153.206] 80 (http) open sent 0, rcvd 0$ netcat -z -vv google.com httpsDNS fwd/rev mismatch: google.com != maa03s16-in-f2.1e100.netDNS fwd/rev mismatch: google.com != maa03s16-in-f6.1e100.netDNS fwd/rev mismatch: google.com != maa03s16-in-f5.1e100.netDNS fwd/rev mismatch: google.com != maa03s16-in-f3.1e100.netDNS fwd/rev mismatch: google.com != maa03s16-in-f8.1e100.netDNS fwd/rev mismatch: google.com != maa03s16-in-f0.1e100.netDNS fwd/rev mismatch: google.com != maa03s16-in-f7.1e100.netDNS fwd/rev mismatch: google.com != maa03s16-in-f4.1e100.netgoogle.com [74.125.236.162] 443 (https) open sent 0, rcvd 0$ netcat -v -z -n -w 1 192.168.1.254 1-1023(UNKNOWN) [192.168.1.254] 989 (ftps-data) open(UNKNOWN) [192.168.1.254] 443 (https) open(UNKNOWN) [192.168.1.254] 53 (domain) open也可以看看 :
使用 nmap 命令扫描网络中开放的端口。手册页 - nc(1), nmap(1) 本文来自云栖社区合作伙伴“Linux中国” 原文发布时间为:2013-04-02. 相关资源:敏捷开发V1.0.pptx