gpt4 book ai didi

c# - 确定 Azure Web 角色的实例 IP 地址

转载 作者:行者123 更新时间:2023-11-30 21:55:43 24 4
gpt4 key购买 nike

我要查找的 IP 地址不是 VIP,也不是分配给角色实例的私有(private) IP 地址,而是您可以使用此配置分配给每个实例的公共(public) IP 地址 :

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

使用 Powershell Cmdlet,可以找到分配给每个实例的 IP 地址,如下所示:

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

这将输出结果,如下所示:

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.186137.135.133.191 是我要在 .net/c# 中检索的 IP 地址 strong>(在角色实例本身中)

对此的任何建议将不胜感激。

谢谢!

最佳答案

您可以使用Azure Management Libraries它们本质上是 Azure 服务管理 API 的包装器,例如 PowerShell Cmdlet。

我编写了一个简单的控制台应用程序,在其中使用这些库来获取云服务所有实例的 IP 地址:

    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())));
}
}
}

您完全可以将此代码用于您的云服务。

关于c# - 确定 Azure Web 角色的实例 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32036049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com