VMware {code} Community
knandapurmath07
Contributor
Contributor

Find hostsystem by findbyip

Hello,

how to retrieve the information about hostsystem object  by using searchindex.findbyip for ipv6,

Findbyip works fine for ipv4. Is there any workaround to ger hostsystem object by using ipv6 address.

Please do provide answer.

Thanks,

Kedarnath

1 Reply
doskiran
Enthusiast
Enthusiast

Try this code to get the ipV6 HostSystem object..

ManagedEntity[] hostManagedEntities = new InventoryNavigator(si.getRootFolder())
.searchManagedEntities("HostSystem");
for (ManagedEntity managedEntity : hostManagedEntities) {
       HostSystem hs = (HostSystem) managedEntity;
       HostVirtualNic[] hvNicArr = hs.getHostNetworkSystem().getNetworkInfo().getVnic();
       for (HostVirtualNic hvNic : hvNicArr) {
            HostVirtualNicSpec spec = hvNic.getSpec();
            HostIpConfig hipConfig = spec.getIp();
            HostIpConfigIpV6AddressConfiguration config = hipConfig.getIpV6Config();
            if (config != null) {
                 HostIpConfigIpV6Address[] ipV6AddressArr = config.getIpV6Address();
                 for (HostIpConfigIpV6Address ipV6Address : ipV6AddressArr) {
                      //Compare with respective ipV6Address and return HostSystem
                     System.out.println(ipV6Address.getIpAddress());
                }
           }
      }
}

 

0 Kudos