如何在Windows上通过python获取几个eternet mac地址?

问题描述

我正在尝试通过python获取几个eternet mac地址。
我尝试了这个python代码,它可以获取一个mac地址。

import getmac
print(getmac.get_mac_address())

在我的计算机中,我安装了Virtual Box,它安装了2个虚拟永恒适配器。我想获取所有包含使用Python的Virtual Box(或Hyper-V)mac地址的mac地址列表。

我正在使用Windows10 x64。
真诚的瑞安。

解决方法

使用netifaces

import netifaces
iface = netifaces.ifaddresses('YOUR NETWORK INTERFACE NAME')[netifaces.AF_LINK]
print(iface['addr'])
,
import netifaces
for nic in netifaces.interfaces():
    iface = netifaces.ifaddresses(nic)[netifaces.AF_LINK]
    if len(iface[0]['addr']) > 0:
        print("mac address: ",iface[0]['addr'])

谢谢Wasif Hasan。