Add a way to get VM's IP address through the API without guest additions (#17324)

Here you can provide suggestions on how to improve the product, website, etc.

Add a way to get VM's IP address through the API without guest additions (#17324)

Postby MartinDachev » 28. Nov 2017, 21:39


[ModEdit, related ticket #17324]

Hello,
I am constantly reading about VirtualBox networking and trying to find a way to get the IP of a VM without installing Guest Additions to it,
mainly when using Bridged Networking. From what I have read from the manual - it should be possible with little additions.

I work in a project that uses the VirtualBox Main API through the VirtualBox Web Service.
I use it to make and configure VMs. The IP needs to be taken automatically, without user interaction and no logging with SSH - because you don't know the IP.


I have read the following from the manual:

"Bridging to a wireless interface is done differently from bridging to a wired interface, because most wireless adapters do not support promiscuous mode. All traffic has to use the MAC address of the host's wireless adapter, and therefore VirtualBox needs to replace the source MAC address in the Ethernet header of an outgoing packet to make sure the reply will be sent to the host interface. When VirtualBox sees an incoming packet with a destination IP address that belongs to one of the virtual machine adapters it replaces the destination MAC address in the Ethernet header with the VM adapter's MAC address and passes it on. VirtualBox examines ARP and DHCP packets in order to learn the IP addresses of virtual machines."

From this statement it looks like VirtualBox already knows the IP address of a VM using Bridged Adapter - yet I haven't found a way to get it without Guest Additions.
Last edited by socratis on 29. Nov 2017, 11:05, edited 1 time in total.
Reason: Added ticket related information.
MartinDachev
 
Posts: 5
Joined: 28. Nov 2017, 21:15

Re: Add a way to get VM's IP address through the API without guest additions

Postby mpack » 29. Nov 2017, 10:57

How would that work?

IP address is not a hardware feature that VirtualBox can read out of some hardware register, it's a feature of a protocol (TCP/IP) implemented by software inside the guest. I.e. it's just a software label, like a filename. How should VirtualBox read the label without GAs to talk to?

And what network protocol are we talking about? If it's "bridged" then the VM is talking pretty much directly to the external network, VirtualBox is barely involved. If it's NAT or Host Only then the IP address was assigned by VirtualBox to begin with, so it has no need to ask the guest what its IP address is.

I'm afraid this proposal isn't making much sense to me.
mpack
Site Moderator
 
Posts: 25493
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Add a way to get VM's IP address through the API without guest additions

Postby socratis » 29. Nov 2017, 11:04

From the VBoxNetFlt, that's what's redirecting everything that comes in to the appropriate VM, isn't it? For every real NIC, VBoxNetFlt attaches itself to that and does all the redirecting, that's at least how I understand it. Could be wrong, it has happened before in the past ;)

MartinDachev opened a ticket as well (#17324) and 'vushakov' said that too much is being read into that paragraph, but that was all he had to say. I asked for clarification. (I hate duplicating discussions).
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
socratis
Site Moderator
 
Posts: 12733
Joined: 22. Oct 2010, 11:03
Location: Greece
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5

Re: Add a way to get VM's IP address through the API without guest additions (#17324)

Postby mpack » 29. Nov 2017, 11:07

That redirection is happening at Ethernet level isn't it? In which case extracting IP addresses would require making a lot of assumptions about the data (i.e. that it's TCP/IP data at all, packet alignment etc), as well as slowing everything down.
mpack
Site Moderator
 
Posts: 25493
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Add a way to get VM's IP address through the API without guest additions (#17324)

Postby michaln » 29. Nov 2017, 12:36

Yes, the assumption that Ethernet equals IP is invalid.

I would say that if the OP knows the MAC address of the VM and knows how the IP address is assigned (which VirtualBox does not know), the OP can also do the MAC->IP lookup.
michaln
Oracle Corporation
 
Posts: 2841
Joined: 19. Dec 2007, 15:45
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Any and all

Re: Add a way to get VM's IP address through the API without guest additions (#17324)

Postby MartinDachev » 30. Nov 2017, 17:25

Okay, thanks for the explanation, and if I understood correctly from what mpack said:
If it's NAT or Host Only then the IP address was assigned by VirtualBox to begin with, so it has no need to ask the guest what its IP address is.


When using NAT or Host Only - the IP is set by VirtualBox. Is that true for NAT Network, I saw that it can have DHCP server, just as Host Only.
Can I get the IP of VMs using some or all of these adapters without using Guest Additions and how? I use the Java API.
MartinDachev
 
Posts: 5
Joined: 28. Nov 2017, 21:15

Re: Add a way to get VM's IP address through the API without guest additions (#17324)

Postby mpack » 30. Nov 2017, 17:33

MartinDachev wrote:When using NAT or Host Only - the IP is set by VirtualBox. Is that true for NAT Network, I saw that it can have DHCP server, just as Host Only.

I'm still not sure what you're asking. NAT and Host Only provide a DHCP server too, as that is the only way to assign an IP address to a guest OS.

It still will not be possible to query a guest if the guest OS has no VBox GAs, so the only way to predict what the IP is will be with what Michaln said: you know the IP address range served up by the DHCP server, you know the order that the VMs start up, so you can predict who gets what address.

I'll say once more that the IP address is not a feature of the hardware, therefore it cannot be discovered by direct querying of the hardware.
mpack
Site Moderator
 
Posts: 25493
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Add a way to get VM's IP address through the API without guest additions (#17324)

Postby MartinDachev » 30. Nov 2017, 18:12

Yes, IP is not hardware. I don't want to ask the VM about it's IP address, I want to get it from the DHCP Server.
When you buy a wireless router, set it up and connect your phone for example, you can see your IP in a DHCP Client Table. There is the MAC address of the phone and the IP assigned.
I can get the MAC address of the VMs (of its Virtual Network Adapters more specifically). So can I get this DHCP Client Table from the DHCP Server? If I can, I will get the IP when I know the MAC address.

Image
MartinDachev
 
Posts: 5
Joined: 28. Nov 2017, 21:15

Re: Add a way to get VM's IP address through the API without guest additions (#17324)

Postby Perryg » 30. Nov 2017, 18:18

"arp -a" should give you a list of mac to ip.
Perryg
Site Moderator
 
Posts: 34279
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Add a way to get VM's IP address through the API without guest additions (#17324)

Postby MartinDachev » 30. Nov 2017, 18:50

I don't have access to the host machine VirtualBox is running on, so I can't do "arp -a". I can't ssh to the machine either.
I am only using the Java API and calling the VirtualBox Web Service remotely. So "arp -a" won't work.
MartinDachev
 
Posts: 5
Joined: 28. Nov 2017, 21:15

Re: Add a way to get VM's IP address through the API without guest additions (#17324)

Postby socratis » 30. Nov 2017, 20:53

For a NATnetwork at least, there is a file that gets generated in the VirtualBox configuration directory, the same directory where the VBoxSVC.log resides, varies by platform. The file is named "<YourNATnetwork>.leases" and it contains a map of IP to MAC and their lease time. Excerpt:
Code: Select all   Expand viewCollapse view
<?xml version="1.0"?>
<Leases version="1.0">
  <Lease mac="08:00:27:a5:bc:47" network="0.0.0.0">
    <Address value="192.168.40.108"/>
    <Time issued="382579" expiration="1200"/>
  </Lease>
  <Lease mac="08:00:27:65:ce:64" network="0.0.0.0">
    <Address value="192.168.40.128"/>
    <Time issued="17777045" expiration="1200"/>
  </Lease>
  <Lease mac="08:00:27:02:e7:60" network="0.0.0.0">
    <Address value="192.168.40.131"/>
    <Time issued="22371676" expiration="1200"/>
  </Lease>
...
</Leases>

I could swear that in older versions there were similar .leases files for the NAT and the HostOnly, but no more.

EDIT: I didn't swear in vain. These files were there in older VirtualBox versions.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
socratis
Site Moderator
 
Posts: 12733
Joined: 22. Oct 2010, 11:03
Location: Greece
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5

Re: Add a way to get VM's IP address through the API without guest additions (#17324)

Postby Perryg » 30. Nov 2017, 21:45

For a NATnetwork at least, there is a file that gets generated in the VirtualBox configuration directory

That's correct but the OP stated that they do not have permission to access the host so all logs and what not will not be available to them. Looks like they are out of luck to me.
Perryg
Site Moderator
 
Posts: 34279
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX


Return to Suggestions

Who is online

Users browsing this forum: No registered users and 2 guests