简体   繁体   English

如何获取WLAN IP地址?

[英]How to get WLAN IP address?

I am getting the IP address list using the following code : 我使用以下代码获取IP地址列表:

string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;

I am getting the proper IP address when device connected to a profile. 当设备连接到配置文件时,我获得了正确的IP地址。 But when we connect the device to PC with USB, IP address is getting changed. 但是当我们用USB将设备连接到PC时,IP地址就会发生变化。 We want to display only the WLAN IP address all the time in our application. 我们希望在我们的应用程序中始终只显示WLAN IP地址。

Is there any API/function which can give only WLAN IP address instead all ? 是否有任何API /功能只能提供WLAN IP地址? or Is there any way to differentiate the WLAN IP from the list of IP addresses return from the above source code ? 或者有没有办法区分WLAN IP与上述源代码返回的IP地址列表?

Maybe somthing like: 也许是这样的事情:

            var address = NetworkInterface
            .GetAllNetworkInterfaces()
            .Where(i => i.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
            .SelectMany(i => i.GetIPProperties().UnicastAddresses)
            .Where(a => a.Address.AddressFamily == AddressFamily.InterNetwork)
            .Select(a => a.Address.ToString())
            .ToList();

From: Github 来自: Github

Found: Stackoverflow 发现: Stackoverflow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM