0

我需要找到一种方法来检索点到站点 VPN(类型:OpenVPN)的当前分配的 IP。

我将 C# 与 Azure 管理 nuget 包一起使用。

对于上下文,只有一种设备连接到点到站点,有时,我需要与他们联系以向他们发送命令。

谢谢。

编辑:

根据 Nancy Xiong 的回复,我想出了以下代码:

            var restClient = RestClient
                .Configure()
                .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                .WithCredentials(creds)
                .Build();

            var networkClient = new NetworkManagementClient(restClient);
            networkClient.SubscriptionId = subscriptionId;

            try
            {
                var connectionHealth =
                    await networkClient.P2sVpnGateways.GetP2sVpnConnectionHealthAsync(resourceGroup,vnetGatewayName);
                var ipAddresses = connectionHealth.VpnClientConnectionHealth.AllocatedIpAddresses;

            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

但是,我得到以下异常:

Microsoft.Rest.Azure.CloudException: The resource type could not be found in the namespace 'Microsoft.Network' for api version '2019-06-01'.

任何想法?

4

1 回答 1

1

您似乎可以privateIpAddress通过 REST API - Get Vpnclient Connection Health获得分配。

对于 .net 的 Azure SDK,您可以通过VpnClientConnectionHealth.AllocatedIpAddresses 属性获取或设置分配给连接的 p2s vpn 客户端的 IP 地址列表

[Newtonsoft.Json.JsonProperty(PropertyName="allocatedIpAddresses")]
public System.Collections.Generic.IList<string> AllocatedIpAddresses { get; set; }
于 2019-09-05T09:37:16.407 回答