IP和端用写在一个文件里面,每行一个IP+端口,中间和冒号分隔,如下的方式:
192.168.1.1:80
192.168.1.2:8080
......
脚本如下:
#!/bin/bash
telnets()
{
results=`(sleep 1;) | telnet $1 $2|grep "]"|wc -l`
if [ $results -eq 0 ]
then
echo "$1 $2 不通" >>/tmp/porttests.txt
else
echo "$1 $2 通" >>/tmp/porttests.txt
fi
}
OLD_IFS="$IFS"
IFS=":"
while read LINE
do
echo $LINE
array=($LINE)
ips=${array[0]}
ports=${array[1]}
telnets $ips $ports
done </tmp/ipsports.txt.bak
IFS="$OLD_IFS"
1748

被折叠的 条评论
为什么被折叠?



