python获取mac地址和ip地址

#!/usr/bin/python
# get ip
import subprocess
def get_ip():
    args='''ifconfig|grep 'inet addr:'|awk '{print $2}'|awk -F':' '{print $2}'|grep -v "127.0.0.1"'''
    t=subprocess.Popen(args,shell=True,stdout=subprocess.PIPE).communicate()[0]
    print(t, type(t))
    t = str(t)
    return t.split('\n')[0]

print(get_ip())


# 获取mac唯一地址
def get_max_address():
    import uuid
    node=uuid.getnode()
    print('node:', node)
    mac=uuid.UUID(int=node).hex[-12:]
    return mac

print(get_max_address())
发布了84 篇原创文章 · 获赞 149 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/feifeiyechuan/article/details/104969743