0
点赞
收藏
分享

微信扫一扫

telnet循环探测服务端口

#!/bin/bash
## $1为端点地址 $2为端口号
## 示例sh telnet_test.sh 127.0.0.1 80
i=0
> ./test.txt
echo "日志保存./test.txt"
while [ $i -lt 2 ]
do
        start_time=`date +%Y%m%d-%H:%M:%S`
        start_time_s=`date +%s`
        RESULT=`echo "" |sleep 0.5| telnet  $1 $2 2> /dev/null`
        if [[ $RESULT =~ "Escape"  ]]; then
                    echo -e "$start_time host $1's tcp port $2 is \033[31mopening\033[0m." |tee -a  ./test.txt
        else
        #Defect: time consuming
                    echo -e "$start_time host $1's tcp port $2 is \033[31mclosed\033[0m."  |tee -a  ./test.txt
        fi
        #sleep 1

done

举报

相关推荐

0 条评论