![持续测试端口 443 上与 example.com 的连接的最佳方法是什么?](https://linux22.com/image/228711/%E6%8C%81%E7%BB%AD%E6%B5%8B%E8%AF%95%E7%AB%AF%E5%8F%A3%20443%20%E4%B8%8A%E4%B8%8E%20example.com%20%E7%9A%84%E8%BF%9E%E6%8E%A5%E7%9A%84%E6%9C%80%E4%BD%B3%E6%96%B9%E6%B3%95%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F.png)
我需要不断尝试连接www.example.com在端口 443。
telnet www.example.com 443
但一旦完成,它将保持连接
[root@localhost ~]# bash c_telnet.sh
Trying 142.250.195.164...
Connected to www.google.com.
Escape character is '^]'.
Connection closed by foreign host.
Trying 142.250.205.228...
Connected to www.google.com.
Escape character is '^]'.
正如您所见,从此输出中无法推断出太多信息。我想测试服务器何时无法访问。
curl -I https://www.google.com
仅当工作足够快时,我才更喜欢卷曲。还有其他选择吗?
我不知道是否可以 ping 通端口 443。
netcat
是一个很棒的工具,但我无法快速安装它,同时telnet
等等curl
都可用。
答案1
据我所知,您也可以使用nmap
Doe 这项工作吗?
nmap -p 443 www.google.com
会回来
Starting Nmap 7.60 ( https://nmap.org ) at 2024-01-31 08:36 CET
Nmap scan report for www.google.com (142.250.201.164)
Host is up (0.0014s latency).
Other addresses for www.google.com (not scanned): 2a00:1450:4007:818::2004
rDNS record for 142.250.201.164: par21s23-in-f4.1e100.net
PORT STATE SERVICE
443/tcp open https
并把 shell 还给你而不用像telnet
以前那样连接
答案2
如果您想尝试连接并连续检查一台主机上的 443 端口,您应该使用 paping帕平@谷歌代码。
用法是 paping -p 443 名称(或 IP),它的反应与 ping 完全相同,因此您可以获得平均返回、失败或超时。
paping -p 443 192.168.xx.xx
paping v1.5.5 - Copyright (c) 2011 Mike Lovell
Connecting to 192.168.xx.xx on TCP 443:
Connected to 192.168.xx.xx: time=15.66ms protocol=TCP port=443
Connected to 192.168.xx.xx: time=31.35ms protocol=TCP port=443
Connected to 192.168.xx.xx: time=31.44ms protocol=TCP port=443
Connected to 192.168.xx.xx: time=15.60ms protocol=TCP port=443
Connection statistics:
Attempted = 4, Connected = 4, Failed = 0 (0.00%)
Approximate connection times:
Minimum = 15.60ms, Maximum = 31.44ms, Average = 23.51ms