Internet连接网络类型是wi-fi/ethernet或其他什么.如何在Windows 8 metro app c#中以编程方式查找

Ash*_*ali 2 microsoft-metro windows-8 winrt-xaml

我正在为Windows 8表面设备开发应用程序.我需要以编程方式找到互联网连接类型我想要找到的是设备连接到Wi-Fi/LanConnection或其他一些网络类型.

谢谢.

Xyr*_*oid 6

您可以找到NetworkAdapter类的网络类型.它具有属性IanaInterfaceType.要检查所有IANA界面,请转到此处

var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
if (profile != null)
{
    var interfaceType = profile.NetworkAdapter.IanaInterfaceType;

    // 71 is WiFi & 6 is Ethernet(LAN)
    if (interfaceType == 71 || interfaceType == 6)
    {
        //TODO:
    }
    // 243 & 244 is 3G/Mobile
    else if (interfaceType == 243 || interfaceType == 244)
    {
        //TODO:
    } 
}
Run Code Online (Sandbox Code Playgroud)