Get VM guests MAC Address Script
Posted by jlchannel - on October 15th, 2008 in Tips | 1 Comment »

This is just to share a simple script – “How to find out VM guest MAC address for each VMware ESX” server as below:
## Script START here
#!/bin/bash
#
# Get VM Guest Mac Address – getmacadd.sh
#
# The getmacadd.sh script must run as root on VMware ESX server.
#
# This work is licensed under a Creative Commons License permitting non-commercial sharing with attribution
#
# Change Log:
# 15 Oct 2008 – version 0.1
#
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
id_check() {
if [ `id -u` -ne 0 ]
then
echo “You must be root to run this script!”
exit
fi
}
id_check
for COUNT in $(vmware-cmd -l); do
echo `echo $COUNT|awk -F’/’ ‘{print $6}’`
echo ” “`echo $COUNT`
echo ” “`cat $COUNT|grep “displayName”`
#MAC Address may refer to “Address” instead of “generatedAddress”
echo ” “`cat $COUNT|grep “generatedAddress”`
echo
done
## Script END here
Result Example:
KULVMSLES01.vmx
/vmfs/volumes/4827fff4-c35f1a3e-299c-002aa0288d45/KULVMSLES01/KULVMSLES01.vmx
displayName = “KULVMSLES01″
ethernet0.generatedAddress = “00:50:56:8a:54:c1″
KULVMWIN2K8.vmx
/vmfs/volumes/47da2ced-93f44308-e601-0025171a435a/KULVMWIN2K8/KULVMWIN2K8.vmx
displayName = “KULVMWIN2K8″
ethernet0.generatedAddress = “00:50:57:8a:6f:be”
Anyway, you can get Linux MAC Address by running command:
/sbin/ifconfig -a | grep “HWaddr” | cut -d ” ” -f 11
Example:
KULVMSLES01:# ifconfig -a | grep “HWaddr” | cut -d ” ” -f 11
00:1A:A0:2C:CA:C1
Please feel free to modify, share and comment to make it perfect.

This work is licensed under a Creative Commons License permitting non-commercial sharing with attribution.

One Response
Thx for this!