zoukankan      html  css  js  c++  java
  • 获取服务器内网地址

    # A类:10.0.0.0 - 10.255.255.255
    # B类:172.16.0.0 - 172.31.255.255
    # C类:192.168.0.0 - 192.168.255.255
    def get_server_inner_ip(outer_ip, password, port):
        dest_client = paramiko.SSHClient()
        dest_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        dest_client.connect(hostname=outer_ip, port=port, username='root', password=password)
        grep_v_string = "grep -v 127.0.0.1"
    
        while True:
            get_inner_ip_cmd = "ifconfig | grep inet | %s | head -1 | awk '{print $2}' | awk -F: '{print $2}'" % grep_v_string
            stdin, stdout, stderr = dest_client.exec_command(get_inner_ip_cmd, get_pty=True)
            inner_ip = str(stdout.read().decode('utf8').split('
    ')[0])
    
            if inner_ip == '':
                return False
    
            temp_list = inner_ip.split('.')
            if not inner_ip.startswith('192.168.') and 
                    not inner_ip.startswith('10.') and 
                    (not int(temp_list[0]) == 172 and not 16 <= int(temp_list[1]) <= 31):
                grep_v_string += " | grep -v %s" % inner_ip
                continue
    
            break
    
        dest_client.close()
    
        return inner_ip
  • 相关阅读:
    安装jar包到本地仓库和远程仓库
    服务之间的资源权限校验
    函数指针
    malloc分配内存
    cuda_vs_报错无法解析的外部错误
    c语言读写文件
    C++使用using namespace std报错分析与解决方案
    MPI环境配置
    c语言学习
    openMP
  • 原文地址:https://www.cnblogs.com/t-road/p/12797096.html
Copyright © 2011-2022 走看看