Search code examples
pythonvmwareesx

Get MAC address of all VMs from VMware


I've a script that I've taken from the VMware documentation to get information of VMs through a python script and the API.

esummary = vm.summary
print("Name       : ", esummary.config.name)
print("IP         : ", esummary.guest.ipAddress)

Which gives me

VM1        : test-vm
IP         : 127.0.0.1

But I want to get a lot more information on each of the Vms. Specifically I'd like the interfaces and MAC address of each VM. Found a few links on how to do this via PowerShell but looking to do it via python instead if it's possible?


Solution

  • Figured it out; found MAC addresses under

    vm.config.hardware.device
    

    so my code to print the MAC address is

    hardware = vm.config.hardware.device
    for d in hardware:
        if hasattr(d, 'macAddress'):
            print('MAC Address   : {}'.format(d.macAddress))