确定Azure的Web角色的实例中的IP地址 [英] Determine Azure Web Role's instance IP address

查看:236
本文介绍了确定Azure的Web角色的实例中的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找的IP地址不是VIP,也不是说是考虑到角色实例的私有IP地址,而公网IP地址的,你可以使用这个配置分配给每个实例

The IP address I am looking for is not the VIP, nor the private IP address that is given to the role instance, but the public IP address that you can assign to each instance using this configuration:

  <NetworkConfiguration>
    <AddressAssignments>
      <InstanceAddress roleName="WebRole1">
        <PublicIPs>
          <PublicIP name="public" />
        </PublicIPs>
      </InstanceAddress>
    </AddressAssignments>
  </NetworkConfiguration>

使用PowerShell cmdlet,1然后能够找到给每个实例类似这样的IP地址

Using Powershell Cmdlets, one is then able to find the IP address given to each instance like this:

PS C:\> Get-AzureService -ServiceName "rr-testservice" | Get-AzureRole -InstanceDetails

将输出结果是这样的:

Which will output the results, like this:

InstanceErrorCode            :
InstanceFaultDomain          : 0
InstanceName                 : WebRole1_IN_0
InstanceSize                 : Small
InstanceStateDetails         :
InstanceStatus               : ReadyRole
InstanceUpgradeDomain        : 0
RoleName                     : WebRole1
DeploymentID                 : 69a82ec9bb094c31a1b79021c0f3bbf2
IPAddress                    : 100.79.164.151
PublicIPAddress              : 137.135.135.186
PublicIPName                 : public
PublicIPIdleTimeoutInMinutes :
PublicIPDomainNameLabel      :
PublicIPFqdns                : {}
ServiceName                  : rr-testservice
OperationDescription         : Get-AzureRole
OperationId                  : 00400634-f65d-095b-947f-411e69b9a053
OperationStatus              : Succeeded

凡在此情况下,IP地址 137.135.135.186 137.135.133.191 都是我找的检索在.NET / C#(在角色实例本身)

Where in this case the IP addresses 137.135.135.186 and 137.135.133.191 are the ones I am looking for to retrieve in .net / c# (in the role instance itself)

在这个任何意见将是极大的AP preciated。

Any advice on this would be greatly appreciated.

谢谢!

推荐答案

您可以使用的 Azure管理库 这基本上是一个包装过的Azure服务管理API 像PowerShell命令。

You could make use of Azure Management Libraries which are essentially a wrapper over Azure Service Management API like PowerShell Cmdlets.

我写的,我利用这些库来迎接我的云服务的所有实例的IP地址,一个简单的控制台应用程序:

I wrote a simple console application where I made use of these libraries to fetch the IP address of all instances of my cloud service:

    static void GetCloudServiceDetails()
    {
        var subscriptionId = "<your azure subscription id>";
        var managementCertDataFromPublishSettingsFile = "<management cert data from a publish settings file>";
        var cert = new X509Certificate2(Convert.FromBase64String(managementCertDataFromPublishSettingsFile));
        var credentials = new CertificateCloudCredentials(subscriptionId, cert);
        var computeManagementClient = new ComputeManagementClient(credentials);
        var cloudServiceName = "<your cloud service name>";
        var cloudServiceDetails = computeManagementClient.HostedServices.GetDetailed(cloudServiceName);
        var deployments = cloudServiceDetails.Deployments;
        foreach (var deployment in deployments)
        {
            Console.WriteLine("Deployment Slot: " + deployment.DeploymentSlot);
            Console.WriteLine("-----------------------------------------------");
            foreach(var instance in deployment.RoleInstances)
            {
                Console.WriteLine("Instance name: " + instance.InstanceName + "; IP Address: " + string.Join(", ", instance.PublicIPs.Select(c => c.Address.ToString())));
            }
        }
    }

您可以很好地利用这个code为您云服务。

You could very well use this code for your Cloud Service.

这篇关于确定Azure的Web角色的实例中的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆