VirtualBox: List guest IPs
Monday, February 13th, 2012
I often clone VirtualBox machines as a quick way to get a fresh box to test some stuff on. The problem is, I don’t know which IP the new clone gets assigned. Fortunately, if you’ve got VirtualBox Guest Additions installed on the guest, you can use the guestproperty to get the IP.
Here’s a quick shell script for listing the v4 IPs of all the running guest virtual machines.
#!/bin/sh VBoxManage list runningvms | cut -d "{" -f1 | sed "s/\"//g" | while read VBOXNAME; do IP=$(VBoxManage guestproperty get "$VBOXNAME" /VirtualBox/GuestInfo/Net/0/V4/IP | cut -d":" -f2) echo "$VBOXNAME: $IP" done
P.S. If you’re using Debian guests: delete the /etc/udev/rules.d/*persistent-net* files. See here for why.