【问题标题】:Azure Management Point-To-Site VPN: Get Connected clients / allocated ipsAzure 管理点到站点 VPN:获取连接的客户端/分配的 ip
【发布时间】:2020-01-08 02:30:20
【问题描述】:

我需要找到一种方法来检索当前为点到站点 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'.

有什么想法吗?

【问题讨论】:

    标签: c# .net azure-virtual-network azure-management-api azure-vpn


    【解决方案1】:

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

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

    [Newtonsoft.Json.JsonProperty(PropertyName="allocatedIpAddresses")]
    public System.Collections.Generic.IList<string> AllocatedIpAddresses { get; set; }
    

    【讨论】:

    • 看起来很有希望...您如何获得 VpnClientConnectionHealth 实例?
    • 尝试使用await azure.networks.VirtualNetworkGateways.GetWithHttpMessagesAsync(string resourceGroupName, string virtualNetworkGatewayName) 之类的内容,请参阅this。或者您也可以考虑在 C# 中调用 API,例如 this
    • 我尝试了两种方式。您链接到的 C# 类是内部的,所以我不能使用它。使用 Rest API 返回 NULL,这实际上解释了为什么 Azure 门户中的设备 ips 列表实际上也是空的。直觉是微软没有为 OpenVPN 连接类型实现这一点。换句话说,我认为目前这根本不可能。无论如何,谢谢你的提示!
    • 如果 Rest API 返回 NULL,我也认为微软没有为 OpenVPN 连接类型实现。
    猜你喜欢
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 2019-06-25
    相关资源
    最近更新 更多