VMware {code} Community
tayky
Contributor
Contributor

Sample to retrieve vm IP address

Hi,

I would like to know if there any sample code to retrieve the ip address of the vms on vcenter?

Thanks in advance.

0 Kudos
7 Replies
maishsk
Expert
Expert

Are you looking to use any specific language? PowerCLI perhaps?

Maish

Maish Saidel-Keesing • @maishsk • http://technodrone.blogspot.com • VMTN Moderator • vExpert • Co-author of VMware vSphere Design
0 Kudos
tayky
Contributor
Contributor

Hi,

I'm actually looking at c# code. I have downloaded the vsphere sample for the vsphere web service sdk but cant seems to find any sample related to retrieve the IP address of VM other than its properties value like vm name.

0 Kudos
rajatscybage
Contributor
Contributor

Hi,

Yes we can retrieve the IpAddress of a VM using

((Vim25Api.VirtualMachineSummary)(objVM)).guest.ipAddress but this API does not return IP Addresses of all the VM of a particular ESX

0 Kudos
lamw
Community Manager
Community Manager

The IP Address being returned from the guest is only available if they're running VMware Tools, it could alos be the case that it's installed but not running. That's how that property is being populated.

0 Kudos
tayky
Contributor
Contributor

Hi,Does anyone have a sample of the code on how it works as i have no idea where to start from? Currently i'm able to retrieve the VM IP address thru vsphere power cli but i looking at using web service sdk instead. Thanks

0 Kudos
rajatscybage
Contributor
Contributor

Hi,

Can you please elaborate on what code exactly do u need. I have retrivied IP address using vpshere sdk only.

object objVM = svc.GetDynamicProperty(ocary[i].obj, "summary"); where svc is webservice object

((Vim25Api.VirtualMachineSummary)(objVM)).guest.ipAddress

0 Kudos
Steve_Jin
Expert
Expert

http://www.doublecloud.org/2010/04/virtual-machine-ip-address-and-mac-address-frequently-confused-co...

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos