每次用下面命令启动vm虚拟机时,发现没办法知道它的IP。

vboxmanage startvm <vmname> --type headless

按照google的一些命令,也查不出来,于是找到一国外哥们儿用arp方法查找在线局域网主机的方法改成了脚本,目前支持单一在线虚拟机,有时间我再改成多用户。

#!/bin/bash

#This shell script can find the ip of running virtualbox system 
#But now(2016/04/18 23:20[beijing]),it only use to find one running virtualbox system 
#此脚本用户找到birdge方式单台在运行的virtualbox虚拟机ip
VMNAME=`vboxmanage list runningvms | awk -F '"' '{print $2}'`
if [ -n $VMNAME ];then
for i in {100..120}
do
ping -c 1 192.168.1.$i &> /dev/null
done

VMMAC=`vboxmanage showvminfo ${VMNAME} |grep 'MAC'|awk '{print $4}'|awk -F',' '{print $1}' | sed -r 's/^(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})/\1:\2:\3:\4:\5:\6/'`
VMIP=`arp -a | grep -i $VMMAC |sed 's/^.*(\(.*\)).*$/\1/'`
echo $VMIP
else
echo "Enn... , not has running virtualbox system."
fi