我用uuid模块取Mac地址的,刚开始很完美,可是后来发现同一台主机取来的Mac地址经常变化,很不靠谱啊,有时候取到的根本不是本机的Mac,也不知道为什么会这样。
求助怎么用Python取一台主机的Mac并且不会自己乱变,另外我的代码贴上来:
def getMac():
mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
return ":".join([mac[e:e+2] for e in range(0,11,2)])
1
fatbean 2015-01-17 21:21:11 +08:00 via iPad
你装了虚拟机就这样了
|
3
s51431980 2015-01-17 23:35:35 +08:00
If you look at the getnode documentation it says that it will return a random long if it fails to detect the mac: "If all attempts to obtain the hardware address fail, we choose a random 48-bit number with its eighth bit set to 1 as recommended in RFC 4122."
|
4
s51431980 2015-01-17 23:36:08 +08:00
|