是否可以检查 ubuntu 服务器上的远程系统的端口是否打开?
我应该能够检查我的机器上的端口(例如:ssh)是否对远程机器开放。
答案1
使用传统 telnet:
[user@lappie ~]$ telnet host 22
Trying ip.adr.tld ...
Connected to host (ip.addr.tld).
Escape character is '^]'.
SSH-2.0-OpenSSH_5.1p1 Debian-5
这是一次成功的尝试。不成功的尝试应该是这样的;
[user@lappie ~]$ telnet host 23
Trying ip.adr.tld ...
telnet: connect to address ip.adr.tld: Connection refused
telnet: Unable to connect to remote host: Connection refused
或者使用 nmap
[user@lappie ~]$ nmap host
Starting Nmap 5.21 ( http://nmap.org ) at 2010-10-07 11:25 CEST
Nmap scan report for host (ip.adr.tld)
Host is up (0.0052s latency).
rDNS record for ip.adr.tld : host.domain.tld
Not shown: 995 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
111/tcp open rpcbind
3000/tcp open ppp
5666/tcp open nrpe
Nmap done: 1 IP address (1 host up) scanned in 0.18 seconds
答案2
这很简单:
nc -zw3 domain.tld 22 && echo "opened" || echo "closed"
-w3
是超时
答案3
答案4
对于脚本,我使用类似下面的内容:
nmap example.com -p 22 -sV --version-all -oG - | grep -iq '22/open'
返回值告诉您端口是否开放!