批量telnet

批量telnet IP port

  • url文件样例:
weblogic@pbxs-app3:~/shelltest/batchTelnet2> cat ipFile.txt 
http://10.133.186.30:7070
http://10.133.240.175:80
http://10.133.240.239:9300
http://10.133.240.239:9000
  • 正则后的IP port
weblogic@pbxs-app3:~/shelltest/batchTelnet2> cat ipList.txt
10.133.186.30 7070
10.133.240.175 80
10.133.240.239 9300
10.133.240.239 9000
  • 批量telnet脚本
 1 #!/bin/bash
 2 # 定义telnet函数
 3 telnetFun(){
 4  sleep 0 | telnet $1 $2 2>log2 1>log1
 5 }
 6 
 7 # 备份文件
 8 num=0
 9 mv log log`date +"%Y%m%d%H%M%S"` 2>>error
10 mv successIP.txt successIP.txt`date +"%Y%m%d%H%M%S"` 2>>error
11 mv failureIP.txt failureIP.txt`date +"%Y%m%d%H%M%S"` 2>>error
12 #若文本为url格式,可解开以下正则,提取IP port 13 #. ./findIPPort.sh 14 #mv ipList.txt ipList.txt`date +%Y%m%d%H%M%S` 15 #过滤配置文件里的所有IP到ipLIst1.txt 16 #grep "http://" ipFile.txt | sed "s/^.*\/\///g"|sed "s/\/.*$//g"|sed "s/:/ /g" > ipList.txt 17 #echo "grep ip port success" 18 19 # 循环输出每一行ip port 20 cat ipList.txt | while read line 21 do 22 num=$(($num+1)) 23 echo -e "\n$num IP and Port is : telnet $line" 24 # <<代表键盘输入,后边跟标识符 ,标识符中间为输入内容,标识符前最好别出现空格 25 telnetFun $line & 26 sleep 0.5 27 # 判断是否有墙 28 cat log2 2>>error | grep "Connection closed by foreign host" | wc -l >res 29 if [ $(cat res) -eq 1 ] 30 then 31 echo -e "\e[1;32mSuccess!\e[0m" 32 echo $line >> successIP.txt 33 else 34 echo -e "\033[31;5mFailure!\033[31;0m" 35 echo $line >> failureIP.txt 36 cat log2 2>>error | grep "Connection refused" | wc -l >res 37 if [ $(cat res) -eq 1 ] 38 then 39 echo -e "\033[31;5mConnection refused!\033[31;0m" 40 echo "Connection refused" >> failureIP.txt 41 fi 42 fi 43 # 输出log 44 echo "$num IP and Port is : $line" >> log 45 cat log1 >> log 46 cat log2 >> log 47 echo -e "----------------------\n" >> log 48 rm log1 log2 res 49 done

 

转载于:https://www.cnblogs.com/daxman/p/9698609.html

你可能感兴趣的:(批量telnet)