zoukankan      html  css  js  c++  java
  • python 获取linux IP地址

    获取IP地址
    
    

    #!/usr/bin/env python
    # -*- coidng:utf-8 -*-
    from subprocess import Popen,PIPE

    def getIP():
        string = str()
        result_list = list()
        dic = dict()
        p =Popen(['ifconfig'],stdout=PIPE)
        content = p.stdout.read()
        lst = [item for item in content.split('
    ') if item]
        for line in lst:
            if line[0].strip():
                result_list.append(string)
                string = line
            else:
                string += line
        result_list.append(string)
        result = [item.split('
    ') for item in result_list if not item.startswith('lo') and item ]
        for line in result:
           dic[line[0].split()[0]]= line[0].split()[6].split(':')[1]
        return dic
  • 相关阅读:
    webpack常见问题 收藏
    ES6 模块
    ES6 Class 类
    ES6 迭代器
    ES6 函数
    ES6 数组
    ES6 对象
    记一次pda(安卓)环境配置流程
    类型转换
    DOM事件
  • 原文地址:https://www.cnblogs.com/simple001/p/8405618.html
Copyright © 2011-2022 走看看