Find/Search for VMWare guests mac address on ESX 4 and ESXi 4 hosts onwards

In the past on vmware you could use the tool vmware-cmd-l to help you find the mac addresses of guests registered to vmware hosts.

You might need to do this if you have an ip address conflict or for some other reason where going through all the guests would be a time consuming and laborious process.

With ESX and ESXi version 4 onwards that command was removed, so the below ash script will allow you to either list the VM’s on a host, or if you use it with an argument it will search for a mac address or part of a mac address.

This script will allow you to search and find a mac address and tie that to a guest name. The script needs to be run on the ESX or ESXi host/s

run it from the command line like below

#./macfinder.sh   < no arguments to list all registered VM’s

or

#./macfinder.sh 00:50:56:00:00:00  < with argument to find specific or part of mac address

 

___________________________ shell script below —————————

#!/bin/ash
# searches current registered vm’s then uses that list to find macAddresses of those

# then greps output for desired mac or part of mac address

vim-cmd vmsvc/getallvms | awk ‘{print $1″:” $2}’ | grep -v Vmid > /tmp/allvms
for lines in `cat /tmp/allvms`do

id=$(echo $lines | awk -F: ‘{print $1}’)

name=$(echo $lines | awk -F: ‘{print $2}’)

mac=$(vim-cmd vmsvc/device.getdevices $id | grep macAddress)

if test $1then
echo $name $mac | grep $1

else echo $name $mac

fi

done

rm -rf /tmp/allvms

You can follow any responses to this entry through the RSS 2.0 feed.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This blog is kept spam free by WP-SpamFree.