美文网首页
批量检测端口连通性

批量检测端口连通性

作者: 繁华丶凋零 | 来源:发表于2019-12-25 11:05 被阅读0次

主脚本check.sh:

#!/bin/bash
echo "" > status

source_ip=($1)
target_ip=($2)
target_port=($3)
for ip_source in `echo ${source_ip[*]}` 
   do   
      for ip_target in `echo -e ${target_ip[*]}` 
         do
            
            for port_target in   `echo -e ${target_port[*]}`
                do
                    ssh support@${ip_source}  -n  "nc -n -w 1 ${ip_target}  ${port_target} >/dev/null 2>&1 && echo ${ip_source} connect ${ip_target} ${port_target} ok || echo ${ip_source} connect ${ip_target} ${port_target} failed "  >> status

             done
    done
done

cat status   

这里是配合jenkins 用的, jenkins配置如下:


图片.png

jenkins job的 Excuse shell 内容如下:


cd /home/jenkins/port_check ;

#source_ip=`echo -e $source_ip| sed 's/ /\n/g'` ;
#target_ip=`echo -e $target_ip| sed 's/ /\n/g'` ;
#target_port=`echo -e $target_port| sed 's/ /\n/g'` ;

bash  check.sh  "$source_ip"   "$target_ip"  "$target_port"

jenkins的参数配置如下格式:


图片.png

相关文章

网友评论

      本文标题:批量检测端口连通性

      本文链接:https://www.haomeiwen.com/subject/ccxcoctx.html