Page 1 of 1
Script to check assigned MAC-addresses in .vbox config
Posted: 3. Jan 2018, 22:22
by myhobby
I'm using VirtualBox for almost everything so I have a lot of VM's. Normally I create a master guest which is copied in case I need a new environment. Currently I have approx 35-40 machines all bridged and most of them via DHCP.
I would like to verify that each machine has it own unique MAC-address assigned. If I'm correct, the assign MAC-address can be found in .vbox XML config file. In my machine all located in /home/vbox. Is there a script or tool available to list the assigned MAC-addresses so we can check if these are all unique ?
Re: Script to check assigned MAC-addresses in .vbox config
Posted: 3. Jan 2018, 23:29
by socratis
Not as a standard feature, no, but you could quickly write one yourself. I don't know your host, but it could be something like:
- List the VMs with 'VBoxManage list vms'
- For every VM in that output get the VM info with 'VBoxManage showvminfo'
- Pass that output to 'grep' to look for "MAC"
- Pass that output to 'awk' to print only the MAC address
For example on my OSX host, the following prints all MAC addresses of all my VMs:
Code: Select all
IFS=$'\t\n';
for i in `VBoxManage list vms | sort | cut -d'"' -f2`; do
VBoxManage showvminfo "$i" | grep MAC | awk '{print $4}' | cut -d',' -f1
done
Thanks for the "idea" BTW, I had never thought of checking that aspect. There were no duplicates among all of my 192 different MACs

Re: Script to check assigned MAC-addresses in .vbox config
Posted: 4. Jan 2018, 00:45
by socratis
I added another "layer" of information if you want; the VM's name after the MAC address. You could then open the output with a text editor and search for the duplicates, put it in a spreadsheet and sort them or anything else that you might like:
Code: Select all
IFS=$'\t\n';
for i in `VBoxManage list vms | sort | cut -d'"' -f2`; do
for j in `VBoxManage showvminfo "$i" | grep MAC | awk '{print $4}' | cut -d',' -f1`; do
echo "$j $i";
done
done
Sample output:
080027FB7E77 AndroVM-TPApps
080027E0866C AndroVM-TPApps
08002791F8B3 Android 4.4.4
0800276C8311 Android 4.4.4
0800278BFB55 Android 7.1
080027254047 Android
080027A1664A Android
080027CC978B Android
080027763292 Android
0800274ADFC4 ChromeOS
...
Re: Script to check assigned MAC-addresses in .vbox config
Posted: 4. Jan 2018, 13:43
by myhobby
This is great help... Let my try this and provide some feedback so others can use this also

Re: Script to check assigned MAC-addresses in .vbox config
Posted: 4. Jan 2018, 15:21
by myhobby
Running Clearos 6.7, created a script and made it executable...
and executed as user vbox
Code: Select all
#!/bin/bash
IFS=$'\t\n';
for i in `VBoxManage list vms | sort | cut -d'"' -f2`; do
for j in `VBoxManage showvminfo "$i" | grep MAC | awk '{print $4}' | cut -d',' -f1`; do
echo "$j $i";
done
done
This indeed creates an overview of the VM machines and it is clearly what I was looking for.... everything listed in VirtualBox.xml is detailed. Machines manually copied and not in the xml are not listed (which is more than fine).
The only small weird thing that happens is an unexpected entry (red). This machine only exists once in the XML.
Code: Select all
bash-4.1$ VBoxManage list vms | sort
"FreePBX 14 Home PRD" {2d0cb8ba-26ce-487f-a48c-86c0a0cc35b0}
"FreePBX Praktijk Visual Dialplan Licensed" {71494983-3c29-43ea-ab8c-39fb056fa715}
"Machine - Download" {1d8e0ecf-a271-4d31-971c-0303bcf1a7a8}
etc
etc
Code: Select all
bash-4.1$ VBoxManage showvminfo "FreePBX Praktijk Visual Dialplan Licensed" | grep MAC | awk '{print $4}'
Results in:
No clue what is causing this, but it works !
Re: Script to check assigned MAC-addresses in .vbox config
Posted: 5. Jan 2018, 09:38
by socratis
myhobby wrote:Machines manually copied and not in the xml are not listed (which is more than fine).
It's not about "fine", it's that VirtualBox doesn't have a clue about that VM, it's not registered.
myhobby wrote:This machine only exists once in the XML.
I'm not sure what that means. The only thing I can think of is that there might be something wrong with the VM name. It there maybe a "tab" character in the name which causes the parsing to fail? I have no clue, my bash scripting abilities are minimal.