简体   繁体   中英

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?

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM