如何在python中获取我的系统Mac加法器

时间:2017-08-27 06:35:35

标签: python mac-address

我尝试在python 3.6.2中获取Mac加法器,我编写了下面的代码来获取它:

xmlhttp.open("POST", "CorRex33.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//Your status change code

xmlhttp.send("WriteFridayHours="+WriteFridayHours);

但它打印错误,例如,如果我的Mac加法器是ff:ff:ff:ff:ff:12,它打印 FF:FF:FF:FF:FF:25。 如何解决?

1 个答案:

答案 0 :(得分:0)

这可以使用netifaces模块实现。

  1. 导入模块:

    >>> import netifaces
    
  2. 获取所有存在的接口

    >>> netifaces.interfaces()  
    ['lo', 'eth0', 'tun2'] 
    
  3. 提取所选界面的Mac地址,例如。 eth0的

    >>> netifaces.ifaddresses('eth0')[netifaces.AF_LINK] 
    [{'addr': '00:00:00:00:00:00', 'broadcast': 'ff:ff:ff:ff:ff:ff'}]