python 获取mac地址
来源:互联网 发布:h5获取json数据实例 编辑:程序博客网 时间:2024/05/17 09:12
通过python获取当前mac地址的方法如下:
(1)通用方法,借助uuid模块
def get_mac_address():
import uuid
node = uuid.getnode()
mac = uuid.UUID(int = node).hex[-12:]
return mac
(2)按照操作系统平台来
def get_mac_address():
'''
@summary: return the MAC address of the computer
'''
import sys
import os
mac = None
if sys.platform == "win32":
for line in os.popen("ipconfig /all"):
print line
if line.lstrip().startswith("Physical Address"):
mac = line.split(":")[1].strip().replace("-", ":")
break
else:
for line in os.popen("/sbin/ifconfig"):
if 'Ether' in line:
mac = line.split()[4]
break
return mac
需要提醒的是,方法一,也就是通过uuid来实现的方法适用性更强一些,因为通过解析popen的数据还受到系统语言环境的影响,比如在中文环境下"ipconfig /all"的结果就包含有中文,要查找mac地址的话就不能查找Physical Address而应该是“物理地址”
- Python获取MAC地址
- Python获取Mac地址
- python 获取mac地址
- python获取mac地址,生成mac地址
- python 获取 mac 地址 的代码举例
- python 获取主机mac ip地址
- python获取本地的IP地址及mac地址
- python获取本机IP、mac地址、计算机名
- python获取本机IP、mac地址、计算机名
- Python获取本机IP、计算机名、mac地址
- python获取本机IP、mac地址、计算机名
- Python获取本机所有网卡的MAC地址
- Python获取本机MAC地址,ip和主机名
- 获取MAC地址
- 获取Mac地址
- 获取Mac地址
- 获取MAC地址
- 获取MAC地址(Err)
- sysfs attr
- Qt中的析构函数
- HNUST 1411 矩阵转置
- 深圳城市交通文明7月份测评指数为84.06分
- afdfd
- python 获取mac地址
- AndroidStudio编码设置
- 进程池与列表循环多参传递
- GreenPlum入门
- 设置Linux服务器只能访问内网,无法访问外网
- leetcode136. Single Number
- hive详细介绍
- SAP S4-HANA BP屏幕增强添加自定义字段(BDT方式)
- UVA