V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
liuxu
V2EX  ›  Linux

写了一个 shell 脚本,用于查找 vbox 后台运行的虚拟机的 IP

  •  
  •   liuxu · Apr 18, 2016 · 3113 views
    This topic created in 3661 days ago, the information mentioned may be changed or developed.

    拙劣的英文望指正 github:https://github.com/liuxu0315/vboxshowrunip

    #!/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
    
    3 replies    2016-04-20 21:41:04 +08:00
    wvuu
        1
    wvuu  
       Apr 19, 2016
    vboxmanage guestproperty enumerate $(vboxmanage list runningvms|awk -F\" '{print $2}')|awk -F': |, ' '/IP/{print $4}'
    churchmice
        2
    churchmice  
       Apr 19, 2016
    你们这些个刷 github 的也够了,是不是 hello world 也要上去来一发?
    liuxu
        3
    liuxu  
    OP
       Apr 20, 2016
    @wvuu 我的桥接,这种方式无效
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3798 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 04:39 · PVG 12:39 · LAX 21:39 · JFK 00:39
    ♥ Do have faith in what you're doing.