I am attempting to figure out what features of Guest Additions I can get working on a MacOS Host and MacOS Guest computer.
We would like to be able to query our VMs such as
Code: Select all
VBoxManage guestproperty enumerate <vmname>
Code: Select all
VBoxManage guestproperty enumerate <vmname>
Code: Select all
#!/bin/bash
#
# Translate a MAC address fetched from VirtualBox into a IP address
#
echo `(arp -a -n | wc -l | awk '{print $1}')` "entries in the ARP table to parse."
MY_MACs=();
IFS=$'\t\n';
# Loop for all the running VMs
for RunningVM in `VBoxManage list runningvms | sort | cut -d'"' -f2`; do
echo -ne $RunningVM;
# Loop for all 32 possible NICs
for i in {1..32}; do
echo -ne "." # Just a progress indicator ;)
# Get a string of the form: macaddressNN="080027abcdef"
# then cut it at the equal ("=") sign
# then cut it at the right length
# then make it all lower case
MY_MAC=$(VBoxManage showvminfo "$RunningVM" --machinereadable | grep macaddress$i | cut -d'=' -f2 | cut -c2-13 | tr '[A-Z]' '[a-z]');
# If the MY_MAC is not empty, format it so that the leading zeroes (in pairs of 2) are not shown,
# and separate each pair number by a colon. That's because this is the way that "arp" outputs the
# MAC addresses as well. Example: "080027ab0def" becomes "8:0:27:ab:d:ef".
if [ "${MY_MAC}" != "" ]; then
MY_MAC=$(echo `expr ${MY_MAC:0:2}`:`expr ${MY_MAC:2:2}`:`expr ${MY_MAC:4:2}`:`expr ${MY_MAC:6:2}`:`expr ${MY_MAC:8:2}`:`expr ${MY_MAC:10:2}`)
MY_MACs[i]="$MY_MAC"
fi
# Loop for all 32 possible NICs
done
echo "." # Restore order for the progress indicator
IFS=$'\n';
# Loop for all ARP table entries.
for MY_ARPentry in $(arp -a -n); do
# Each entry in the "arp -a -n" output looks like (space separated):
#
# ? (192.168.20.102) at (incomplete) on vboxnet0 ifscope [ethernet]
# 1 2 3 4 5 6 7 <---- These are the spaces
#
# Use the space as a delimiter to get the MAC, and the parentheses to get the IP.
MY_ARP_MAC=$(echo ${MY_ARPentry} | cut -d' ' -f4 | cut -d' ' -f3)
MY_ARP_IP=$( echo ${MY_ARPentry} | cut -d'(' -f2 | cut -d')' -f1)
# Now loop through each of the MAC addresses stored in the 'VBoxManage showvminfo'.
# If you find a match, print it out.
for MY_MAC in "${MY_MACs[@]}"; do
if test "$MY_MAC" = "$MY_ARP_MAC"; then
unset IFS
MY_ARP_MAC="$(printf "%02X:%02X:%02X:%02X:%02X:%02X" 0x${MY_ARP_MAC//:/ 0x})"
echo " MAC: $MY_ARP_MAC IP: $MY_ARP_IP"
fi
# Loop for all MAC addresses.
done
# Loop for all ARP table entries.
done
# Loop for all the running VMs
done