Linux 版本:
VMware® Workstation 15 Pro(15.5.2 build-15785246) / Hyper-v
CentOS7(3.10.0-957.el7.x86_64)
Windows 版本:
版本 Windows 10 教育版
版本号 20H2
1.telnet 命令
$ telnet <ip_address> <port_number>
适用范围:windows(需要打开 Telnet 功能)、linux(可能需要安装:yum install telnet)
[root@node1 ~]#telnet baidu.com 80
Trying 39.156.69.79...
Connected to baidu.com.
Escape character is '^]'.
Connection closed by foreign host.
2.nc 命令
$ nc -vz <host> <port_number>
适用范围:linux
[root@node1 ~]#nc -vz 10.10.0.42 80
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connection refused.
[root@node1 ~]#nc -vz daidu.com 80
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 52.128.23.153:80.
Ncat: 0 bytes sent, 0 bytes received in 0.64 seconds.
CentOS 自带,如果需要安装:yum install netcat
3.nmap 命令
$ nmap -p <port_number> <ip_address>
适用范围:linux(yum install nmap)
[root@node1 ~]#nmap -p 1-100 192.168.16.1
Starting Nmap 6.40 ( http://nmap.org ) at 2021-04-08 19:44 CST
Nmap scan report for 192.168.16.1
Host is up (0.0016s latency).
All 100 scanned ports on 192.168.16.1 are closed
MAC Address: 00:50:56:C0:00:08 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 1.80 seconds
注意nmap可能产生法律问题
4.PowerShell 自带命令
$ Test-NetConnection <ip_address> -p <port_number>
适用范围:windows
PS C:\Users\Aaron> Test-NetConnection 192.168.16.138 -p 80
ComputerName : 192.168.16.138
RemoteAddress : 192.168.16.138
RemotePort : 80
InterfaceAlias : VMware Network Adapter VMnet8
SourceAddress : 192.168.16.1
TcpTestSucceeded : True
向远程主机发送“ ping”请求意味着您正在使用 ICMP 协议来检查网络连接。ICMP 主要用于诊断将阻止您访问主机的网络问题。当您 ping 端口时,实际上是在计算机和特定端口上的远程主机之间建立 TCP连接。
至于这些命令之间有何不同,有待进一步学习。