Whether the batch telnet network ports are connected

        For the k8s cluster, when a new node is added to the cluster, if it is the IP of the same network segment, there is no need to consider whether the ports are connected. If the IP of a different network segment is added to the cluster, it needs to be considered that the computing node The problem of port communication with the master node.

        Port information of components on the master node set in the cluster:

method one:

 What I need to operate is: the tcp and udp ports in the new node node and the master node

View the contents of the script

 View the content of iplist.txt, the format is ip:port 

 The result after executing the script is as follows:

 

The following is the script content:

# cat telnet_all.sh

ipfile=$1
curpath=$(readlink -f "$(dirname "$0")")
lines=($(cat $curpath'/'$ipfile))
len=${#lines[@]}
for ((i=0; i<$len; i++))
do
  line=${lines[$i]}
   array=(${line//:/ })
   ip=${array[0]}
   port=${array[1]}
   sh telnet_one.sh $ip $port
done
# cat telnet_one.sh
ip=$1
port=$2
timeoutSec=5
echo -e '\x1dclose\x0d' | timeout --signal=9 $timeoutSec telnet $ip $port
if [ $? -eq 0 ];then
    echo -e "$(date + "%Y-%m-%d") $(date + "%H:%M:%S") [INFO] $hostname 与 $ip:$port 网络通" | tee -a result.txt 2>&1
else
    echo -e "$(date + "%Y-%m-%d") $(date + "%H:%M:%S") [WARNING] $hostname 与 $ip:$port 网络不通" | tee -a result.txt 2>&1
fi

Method 2:

# cat check_tenlte.sh
cat iplist.txt | while read line
do
    result=`echo -e "\n" | telnet $i 2>/dev/null | grep Connected | wc -l`
    if [ $result -eq "1" ]; then
        echo "$i Network is Open."
    else
        echo "$i Network is Closed."
    fi
done

The format of iplist.txt is:

192.168.2.1 1201
192.168.2.2 1202
192.168.2.3 1203
192.168.2.4 1204
192.168.2.5 1205

Guess you like

Origin blog.csdn.net/red_sky_blue/article/details/126507667