方法一. 常用telnet 118.10.6.128 88方式测试远程主机端口是否打开。
telnet baidu.com 80
Trying 123.125.114.144...
Connected to baidu.com (123.125.114.144). #==>出现Connected表示连通了,说明百度的80端口开放的
Escape character is '^]'. #==>按“ctrl+]”退出此地。
^]
telnet> quit
Connection closed.
测试IP地址:
# telnet 108.5.16.139 7506
Trying 108.5.16.139...
Connected to static-108-5-16-139.nycmny.fios.verizon.net (108.5.16.139). #==>出
现Connected表示连通了,说明108.5.16.139的7506端口开放的
Escape character is '^]'. #==>按“ctrl+]”退出此地
^]
telnet> quit
Connection closed.
如果写脚本通过telnet检查端口可以用下面的方法:
echo -e "\n"|telnet baidu.com 80|grep Connected
Connection closed by foreign host.
Connected to baidu.com (123.125.114.144).
方法二. nmap ip -p port 测试端口
nmap ip 显示全部打开的端口,根据显示close/open确定端口是否打开。
nmap etiantian.org -p 80
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2012-07-22 17:22 PDT
Interesting ports on 211.100.98.99:
PORT STATE SERVICE
80/tcp open http
Nmap finished: 1 IP address (1 host up) scanned in 0.417 seconds
如果写脚本通过nmap检查端口可以用下面的方法:
PORT_COUNT=`nmap $ip_add -p $port|grep open|wc -l`
[[ $PORT_COUNT -ge 1 ]] && echo "$ip_add $port is ok." || echo "$ip_add $port is unknown."
nmap 121.40.71.117 -p 8090| egrep "8090/tcp\s\w+\s" | grep open
方法三. 通过nc命令检查
nc -v host port
nc -w 10 8.8.8.8 53 && echo ok ||echo no
监控网页的响应时间
curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "http://www.kklinux.com"
监控站点可用性
curl -o /dev/null -s -w %{http_code} "http://172.16.13.44/index.html"
另外如果查询本地端口
netstat –apn | grep [端口号]