zoukankan      html  css  js  c++  java
  • Shell检测IP和端口

    检测IP

    Eg.

    RET_FAIL=1
    RET_SUCCESS=0
    # check ip is reach
    #   input ip / ip:port
    function ip_is_reach()
    {
        l_host=${1}
        l_host_ip=$( echo ${l_host} | cut -f1 -d ':'  )
        detect_log "ping host ${l_host_ip}"
        ping -c2 -i0.1 -W2 ${l_host_ip} 2>&1 > /dev/zero
        if [ $? != 0 ]; then
            return ${RET_FAIL};
        else
            return ${RET_SUCCESS};
        fi
    }
    

    检测IP和端口

    Eg.

    RET_FAIL=1
    RET_SUCCESS=0
    # check ip:port is reach
    #   input: ip:port
    function ip_port_is_reach(){
        l_host=${1}
    
        l_host_ip=""
        l_host_port=""
    
        # "ip:host"解析成l_host_ip和l_host_port
        if [ `echo  ${l_host} | grep -c ":"` -ne '0' ]; then
            l_host_ip=$(echo ${l_host} | cut -f1 -d ':' )
            l_host_port=$(echo ${l_host} | cut -f2 -d ':' )
        fi
    
        result=`echo -e "
    " | telnet ${l_host_ip} ${l_host_port} 2>/dev/null | grep Connected | wc -l`
        if [ $result != 1 ]; then
            return ${RET_FAIL};
        else
            return ${RET_SUCCESS};
        fi
    }
    
  • 相关阅读:
    03.yaml语法和playbook写法
    02.ansible的常用模块
    01.ansible基本配置与使用
    24.删除表名
    23.MySQL的备份与恢复
    22.更改表名
    MySQL的表操作
    MySQL的库操作
    MySQL的用户管理
    数据库及MySQL概述
  • 原文地址:https://www.cnblogs.com/delta1037/p/13435022.html
Copyright © 2011-2022 走看看