How to get the IP Address of a virtual machine with Java sdk

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
aandis
Posts: 5
Joined: 3. Feb 2015, 19:23

How to get the IP Address of a virtual machine with Java sdk

Post by aandis »

VirtualBox version - 4.3.10_Ubuntu r93012
VirtualBox API Version - 4.3.10
Connection Type - WebServer
Language - Java
OS - Ubuntu 14.04

How do I get the IPv4 address with the Java sdk, of a virtual machine which uses a bridged adapter? Is it possible?
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: How to get the IP Address of a virtual machine with Java

Post by noteirak »

You can retrieve that info using the following method - replace <nicId> by the approprivate NIC index :

Code: Select all

IMachine::getGuestPropertyValue("/VirtualBox/GuestInfo/Net/<nicId>/V4/IP");
You will need the guest additions running in the VM to retrieve such info.
If you are not sure what is the right index, you can check the MAC address of the NIC in the VM config with the guest reported MAC given with the guest property /VirtualBox/GuestInfo/Net/<nicId>/MAC
Finally, the full guest NIC count is available using /VirtualBox/GuestInfo/Net/Count
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply