linux expect配合telnet批量测试远端端口

linux expect配合telnet批量测试远端端口

while read读取host文件,使用expect自动处理telnet后grep

脚本并发,host地址不限数量,3秒结束!

host.txt文件如下

#IPADD          PORT
172.16.207.128  22
172.16.207.129  22
172.16.207.131  80
172.16.207.132  22
172.16.207.132  8080
172.16.207.132  8005
192.168.0.222   333

测试端口脚本如下:

#!/bin/bash
HOST=/root/host.txt
OUTPUT=/tmp/telnet_error.log
###############以下内容无需修改##############
echo starting
echo "telnet error!!!"> $OUTPUT
while read ip
do
(
echo $ip|grep  "^[0-9]" >/dev/nullvi
if [ $? -eq 0 ];then
                expect <<EOF  > "$ip"
                set timeout 3;
                spawn telnet $ip
                expect eof
EOF
                grep "Escape character" "$ip" >/dev/null
                if [ ! $? -eq 0 ];then
                grep 'spawn' "$ip" |awk '$1=$2=" "{print}' >> $OUTPUT
                fi
                rm -rf "$ip"
fi
)&


done<$HOST
wait
echo "Output:$OUTPUT"
cat $OUTPUT 
good good study, day day up!

发表评论

textsms
account_circle
email

linux expect配合telnet批量测试远端端口
while read读取host文件,使用expect自动处理telnet后grep 脚本并发,host地址不限数量,3秒结束! host.txt文件如下 #IPADD PORT 172.16.207.128 22 172.16.207.129 …
扫描二维码继续阅读
2022-07-02