VMware {code} Community
ahe
Contributor
Contributor

there are two network card in a viral machine,in other words it has two IP adresses,how do i get all of the ip adresses?

There are two network card in a  virtual machine,in other words it has two IP adresses,how do i get all of the ip adresses?
Each GuestInfo class is only one IP address?Where is the other IP address stored?

Thank you!

0 Kudos
1 Reply
doskiran
Enthusiast
Enthusiast

Using the GuestNicInfo class from VM GuestInfo class to retrive the all VM ip addresses. Below is the code sample.

public static void getVMIPAddresses(VirtualMachine vm) {
        GuestInfo guest = vm.getGuest();
        if (null != guest) {
            GuestNicInfo getNet[] = guest.getNet();
            if (null != getNet) {
                for (int i = 0; i < getNet.length; i++) {
                    if (getNet[i].getIpAddress() != null) {
                        for (String ip : getNet[i].getIpAddress()) {
                            System.out.println("Ipaddress " + ip);
                        }
                    }
                }
            }
        }
    }

0 Kudos