Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9167204
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: 服务器与存储

2020-04-30 19:46:06

1.以":"作为分隔符,将IP及port信息贴入ip_port_info文件中,第一列为IP,第二列为端口


192.168.233.155:2337
192.168.233.155:2338
192.168.233.155:2339
192.168.233.136:3015
192.168.233.155:3022
192.168.233.136:3299
192.168.233.136:4000
2.脚本内容


#!/bin/bash


>temp_file
>check_result


echo "ip port result" >> check_result


cat ip_port_info |while read line
do
        ip=$(echo "${line}" |awk -F ":" '{print $1}')
        port=$(echo "${line}" |awk -F ":" '{print $2}')
        ssh -o ConnectTimeout=10 -o BatchMode=yes -o StrictHostKeyChecking=no -p ${port} test@${ip} >> temp_file 2>&1
        value=$(cat temp_file |tail -n 1 |grep -E 'Connection timed out during|gssapi-with-mic' |wc -l)
        echo ${value}
        if [ ${value} -eq 1 ]
        then
                echo "${ip} ${port} true" >> check_result
        else
                echo "${ip} ${port} false" >> check_result
        fi
        echo "" >temp_file 
done
3.使用方法


nohup sh check_port.sh &即可


4.输出结果


ip port result
192.168.233.155 2337 true
192.168.233.155 2338 true
192.168.233.155 2339 true
192.168.233.136 3015 false
192.168.233.155 3022 false
192.168.233.136 3299 true
192.168.233.136 4000 true
阅读(749) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~