Reputation: 85
When associating a cloud service with a specific virtual network, the instance automatically gets an IP from the selected subnet range.
Is there a way to know this IP dynamically from within the instance itself? If so, is this information available as soon as the instance is created, for instance at the time when startup tasks are executed?
If not, is there a way to get this IP at any time after the instance is created, from outside the instance, programmatically?
I prefer a PowerShell solution, but anything would do.
Thanks.
Upvotes: 2
Views: 1579
Reputation: 30903
If you are from the instance, the IP Address is assigned at boot time. So by the time a start-up task is executed (PaaS / Cloud Service) you can determine the IP Address by just enumerating the network cards. Or getting en IP Endpoint.
A sample powershell (which has never been tested) would look something like this:
[Reflection.Assembly]::LoadWithPartialName("Microsoft.WindowsAzure.ServiceRuntime")
$ipEndpoint = [Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint
Now you have the $ipEndpoint
variable which is of .NET type IPEndpoint
and holds the local IP Address of the VM.
Upvotes: 1