前提条件:
apt-get install netcat-openbsd
方法一:
vi multiping.sh
添加如下内容:
#!/bin/bash
while :; do for i in '192.168.1.1 80' 'www.baidu.com 443' '192.168.2.50 770' 'www.163.com 443'; do nc -w 10 -zv $i; done;echo "等待测试。。。。。。"; sleep 10; clear; done
增加执行权限即可,其中in后边单引号内是IP地址和端口号,多个地址可以顺序给出即可。
方法二:
vi multiping.sh
添加如下内容:
while :; do cat multiping.txt |while read i; do nc -w 10 -zv $i; done; echo "等待测试。。。。。。"; sleep 10; clear; done
vi multiping.txt
添加如下格式内容:
www.baidu.com 443
www.163.com 443
文件格式为ip port,每一行为一条内容,以回车键结束。
为multiping.sh增加执行权限。
测试结果看起来像这样:
Connection to www.baidu.com 443 port [tcp/https] succeeded!
Connection to www.163.com 443 port [tcp/https] succeeded!
Connection to www.163.com 80 port [tcp/http] succeeded!
nc: connect to mail.163.com port 25 (tcp) failed: Connection refused
nc: connect to mail.163.com port 25 (tcp) failed: Connection refused
nc: connect to mail.163.com port 25 (tcp) failed: Connection refused
nc: connect to mail.163.com port 110 (tcp) failed: Connection refused
nc: connect to mail.163.com port 110 (tcp) failed: Connection refused
nc: connect to mail.163.com port 110 (tcp) failed: Connection refused
Connection to www.baidu.com 80 port [tcp/http] succeeded!
Connection to www.sohu.com 443 port [tcp/https] succeeded!
Connection to www.linux.cn 443 port [tcp/https] succeeded!
nc: connect to www.linuxidc.com port 21 (tcp) timed out: Operation now in progress
nc: connect to www.linuxidc.com port 21 (tcp) timed out: Operation now in progress
等待测试。。。。。。
失败问题:
使用如下:
IPF=$'\n'; for i in $(cat multiping.txt); do nc -w 10 -zv $i; done
nc总是报错。原因不详。不知道哪位高手可以解释和解决一下子。