【发布时间】:2023-03-18 07:34:01
【问题描述】:
我有关于获取 IP 地址的问题,我参考了一些在线资源和一些答案,但我仍然无法修复它, https://forums.virtualbox.org/viewtopic.php?f=34&t=65910 - 与我的问题最匹配的链接。
配置:
Host Machine : Windows 8
Guest : Slitaz 4.0
VirtualBox : 4.3.24
VirtualBox Java API : 4.3
Adapter in VM : Host Only Adapter
Slitaz Guest Additions are also installed.
我使用 VirtualBox API 创建了一个 Java 程序,我基本上可以在 VirtualBox 中连接、克隆和启动 VM。但我无法做的是获取机器的 IP 地址。 (为什么我需要 IP 是因为我想通过 SSH 进入那台机器,使用 JSCH java 库并执行一些进程)
这是我迄今为止尝试过的,
根据上面提到的链接,
machine.getGuestPropertyValue("/VirtualBox/GuestInfo/Net/<nicid>/V4/IP") - returns empty result
machine.getGuestPropertyValue("/VirtualBox/GuestInfo/Net/Count") - returns empty result
machine.getGuestPropertyValue("/VirtualBox/GuestInfo/Net/<nicid>/MAC") - return empty result
machine.getGuestPropertyValue("/VirtualBox/GuestInfo/OS/Release") - this gives me release version of linux - which is ok
我又试了一件事,到底有多少属性可用
org.virtualbox_4_3.Holder<List<String>> tempList = new Holder<List<String>>();
org.virtualbox_4_3.Holder<List<String>> tempList1 = new Holder<List<String>>();
Holder<List<Long>> tempList2 = new Holder<List<Long>>();
org.virtualbox_4_3.Holder<List<String>> tempList3 = new Holder<List<String>>();
machine.enumerateGuestProperties("",tempList, tempList1,tempList2,tempList3);
现在在 templist 中,我得到所有可用属性的名称,在 tempList1 中它是值。
[/VirtualBox/GuestInfo/OS/Product, /VirtualBox/HostInfo/GUI/LanguageID, /VirtualBox/HostInfo/VBoxVerExt, /VirtualBox/GuestAdd/Vbgl/Video/SavedMode, /VirtualBox/GuestInfo/OS/Version, /VirtualBox/GuestAdd/VersionExt, /VirtualBox/GuestAdd/Revision, /VirtualBox/HostGuest/SysprepExec, /VirtualBox/GuestAdd/Vbgl/Video/0, /VirtualBox/HostGuest/SysprepArgs, /VirtualBox/GuestAdd/Version, /VirtualBox/HostInfo/VBoxRev, /VirtualBox/HostInfo/VBoxVer, /VirtualBox/GuestInfo/OS/Release, /VirtualBox/GuestAdd/HostVerLastChecked]
这就是原因,我认为这行得通
machine.getGuestPropertyValue("/VirtualBox/GuestInfo/OS/Release") - this gives me release version of linux - which is ok
但是没有与IP相关的财产。此外,我不确定 nicid 到底是什么,以及如何使用 API 来获取它,它是 VM 中适配器的 mac 地址,还是其他东西。
machine.getGuestPropertyValue("/VirtualBox/GuestInfo/Net/<nicid>/V4/IP")
有人可以在这里帮助我或指导适当的方向吗?
【问题讨论】:
标签: java virtual-machine virtualbox ip-address