Search code examples
pythonwindowsmacosnic

How to get several eternet mac address by python at windows?


I'm trying to get several eternet mac addresses by python.
I tried this python code, and it works to get the first mac address.

import getmac
print(getmac.get_mac_address())

In my computer, I installed Virtual Box, and it installed 2 virtual eternal adapters. I want to get all mac address lists which include Virtual Box(or Hyper-V) mac address with Python.

I'm using Windows10 x64.
Sincerely Ryan.


Solution

  • Use netifaces:

    import netifaces
    iface = netifaces.ifaddresses('YOUR NETWORK INTERFACE NAME')[netifaces.AF_LINK]
    print(iface['addr'])