【问题标题】:VirtualBox Java API - Get IP Address of VM in VirtualBoxVirtualBox Java API - 在 VirtualBox 中获取虚拟机的 IP 地址
【发布时间】: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/&lt;nicid&gt;/V4/IP")

有人可以在这里帮助我或指导适当的方向吗?

【问题讨论】:

    标签: java virtual-machine virtualbox ip-address


    【解决方案1】:

    感谢虚拟盒子论坛,这里是解决问题的链接 https://forums.virtualbox.org/viewtopic.php?f=34&t=66788&sid=bc4d34a5ad65fe3ff5006f91c8690817

    但是总结一下解决方案,

    1. 已确保在slitaz 上添加的客人与虚拟盒版本匹配的客人兼容(正确的版本)。
    2. 问题是VBoxServiceSlitaz 的引导过程中没有自动启动。
    3. 所以 etc/rcS.conf 文件被编辑以在 LOAD_MODULES 中添加额外的程序 .............. /usr/sbin/VBoxService(使用which VBoxService获取服务路径)
    4. 现在重新启动 Slitaz 时,此进程正在运行,并且 vboxmanage guestproperty enumerate '&lt;vmname&gt;'列出所有配置
    5. 一个感兴趣的是, Name: /VirtualBox/GuestInfo/Net/0/V4/IP, value: 192.168.56.101, timestamp: 1427467107101664501, flags:

    希望对某人有所帮助!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 2016-02-02
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      相关资源
      最近更新 更多