Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
liuxu
V2EX  ›  Linux

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

  •  
  •   liuxu · Apr 18, 2016 · 3145 views
    This topic created in 3681 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   ·   4837 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 09:50 · PVG 17:50 · LAX 02:50 · JFK 05:50
    ♥ Do have faith in what you're doing.