VMware {code} Community
7hillsup
Contributor
Contributor

The class vim.vm.GuestInfo is not giving primary IPAddress of Virtual Machine


I am following below document to get primary IPAddress for Virtual Machines, as per the document I am expecting the primary IPAddress of the Virtual Machine,  but unexpectedly it is giving the Secondary IPAddress( Internal IPAddress )

https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538c...

Note:
I am using VI SDK to collect Host and VMs guest tools information, Here i am facing issues for virtual machines which have windows server operating system.

Can some one please help me on how to identify the primary IPAddress of VM in this case.

0 Kudos
2 Replies
doskiran
Enthusiast
Enthusiast

Sample program to print the Virtual machine network details(Nic name, IPv4, Mac, Nic Key, Portgroup) using VI java API(vSphere Management SDK). - PrintVMNetworkDetails.java
Output:

Network Adatpter     IP4Address         Mac                  Key      Portgroup                                                                                         
----------------     ----------         ---                  ---      ---------                                                                                       
Network adapter 1    10.10.10.6         00:15:23:31:c9:22    4000     VM Network                                                                                       
Network adapter 2    10.20.20.7         07:89:61:14:38:66    4001     dvPortgroup                                                                                       

Ipaddesses of each vNIC:

GuestNicInfo[] nicArr = vm.getGuest().getNet();
for (GuestNicInfo nic : nicArr) {
	NetIpConfigInfoIpAddress[] netIpArr = nic.getIpConfig().getIpAddress();
	for (NetIpConfigInfoIpAddress netIp : netIpArr) {
		System.out.println("Ipaddress::" + netIp.getIpAddress());
    }
}



0 Kudos
7hillsup
Contributor
Contributor

Hi Kiran,

Thanks for your time and help and sorry for my late reply.
I am expecting a single primary ip address instead of all the ip address which are configured, how to set and get a preferred ip address from vm guest tools. 

As per the below page, we should get the primary ip address for the Virtual machine from the guest tools, but we are receiving secondary ip address for windows Operating System devices. Can you please help me.

https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538c...

0 Kudos