#!/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 33[31mopening 33[0m." |tee -a ./test.txt
else
#Defect: time consuming
echo -e "$start_time host $1's tcp port $2 is 33[31mclosed 33[0m." |tee -a ./test.txt
fi
#sleep 1
done
服务器租用托管,机房租用托管,主机租用托管,https://www.e1idc.com