python 获取mac地址的两种方法,pythonmac,1)通用方法,借助uui
python 获取mac地址的两种方法,pythonmac,1)通用方法,借助uui
1)通用方法,借助uuid模块```pythondef get_mac_address(): import uuid node = uuid.getnode() mac = uuid.UUID(int = node).hex[-12:] return mac
(2)按照操作系统平台来 ```pythondef 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地址的话就不能查找PhysicalAddress;而应该是“物理地址”
相关内容
- python3 连接sqlite实例,python3sqlite实例,python3连接sql
- python读取windows系统信息,python读取系统信息,需要使用
- Python 实现一个小功能: 删除某路径下文件及文件夹的
- python获取网络时间和本地时间,python获取网络,今天我们
- python编写的一个简单的扫描端口的程序,python编写端口
- python监控网站运行异常并发送邮件,python监控发送邮件
- python开发简单socket程序在两台电脑之间传输消息,pyt
- Python比较两个图片的相似度,,这段代码实用pil模块比
- 简单爬虫返回列表,爬虫返回列表,import reimp
- 统计贴吧股票吧某天的回帖量,贴吧股票某天回帖,#
评论关闭