获取 MAC 地址 [英] Getting MAC Address

查看:43
本文介绍了获取 MAC 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种在运行时确定计算机 MAC 地址的跨平台方法.对于 Windows,可以使用wmi"模块,而在 Linux 下我能找到的唯一方法是运行 ifconfig 并在其输出中运行正则表达式.我不喜欢使用只能在一个操作系统上运行的包,并且解析另一个程序的输出似乎不是很优雅,更不用说容易出错了.

I need a cross platform method of determining the MAC address of a computer at run time. For windows the 'wmi' module can be used and the only method under Linux I could find was to run ifconfig and run a regex across its output. I don't like using a package that only works on one OS, and parsing the output of another program doesn't seem very elegant not to mention error prone.

有谁知道获取MAC地址的跨平台方法(windows和linux)?如果没有,有没有人知道比我上面列出的那些更优雅的方法?

Does anyone know a cross platform method (windows and linux) method to get the MAC address? If not, does anyone know any more elegant methods then those I listed above?

推荐答案

Python 2.5 包含一个 uuid 实现(至少在一个版本中)需要 mac 地址.您可以轻松地将mac查找功能导入到您自己的代码中:

Python 2.5 includes an uuid implementation which (in at least one version) needs the mac address. You can import the mac finding function into your own code easily:

from uuid import getnode as get_mac
mac = get_mac()

返回值为 48 位整数形式的 mac 地址.

The return value is the mac address as 48 bit integer.

这篇关于获取 MAC 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆