简体   繁体   English

如何判断手机是通过wifi连接的,还是可以通过C#访问移动互联网的?

[英]How can I tell if a phone is connected by wifi or has access to mobile internet via C#?

When the phone is in the local network it has ip 192.168.0.x when it is outside wifi access it uses internet connection provided by mobile network(the internet accessed when you have sim inside the phone). 当手机在本地网络中时,当它在wifi外时它的IP为192.168.0.x ,它使用移动网络提供的互联网连接(当您在手机中装有sim卡时可以访问互联网)。

How to determine by C# which kind of connection is used at the time? 如何通过C#确定当时使用哪种连接?

EDIT: 编辑:

NetworkInterfaceInfo netInterfaceInfo = socket.GetCurrentNetworkInterface();
    var type = netInterfaceInfo.InterfaceType;
    var subType = netInterfaceInfo.InterfaceSubtype;

You can try this method to check network states: 您可以尝试使用此方法检查网络状态:

public static string GetNetStates()
{
    var info = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
    switch (info)
    {
        case NetworkInterfaceType.MobileBroadbandCdma:
            return "CDMA";
        case NetworkInterfaceType.MobileBroadbandGsm:
            return "CSM";
        case NetworkInterfaceType.Wireless80211:
            return "WiFi";
        case NetworkInterfaceType.Ethernet:
            return "Ethernet";
        case NetworkInterfaceType.None:
            return "None";
        default:
            return "Other";
    }   
}

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

相关问题 如何确定我是否在Windows Phone 8.1(通用应用程序)中连接到WiFi或移动网络? - How can I determine whether I am connected to WiFi or a mobile network in Windows Phone 8.1 (Universal app)? c#如果我连接到VPN,应用程序将无法访问Internet - c# Application cannot access the internet if I am connected to a VPN 如何判断是否连接到互联网 - How to tell if connected to internet 通过C#程序拨打手机 - Dial mobile phone via C# program 如何获得“在 c# 桌面应用程序中调用 API 时使用了多少网络数据(移动或 WiFi)” - How can I get “How many Network data(Mobile or WiFi) used when I call API in c# desktop application” 如何在winforms c#中绘制通过“节点”连接的多条线? - How can I draw multiple lines connected via “nodes” in winforms c#? "如何通过 C# 连接到通过 ESP32 打开的本地 wifi 网络并从传感器传输数据?" - How can I connect to the local wifi network opened via ESP32 via C# and transfer the data from the sensors? 如何通过反射判断 C# 方法是否为 async/await? - How can I tell if a C# method is async/await via reflection? UWP C#-访问手机文件 - UWP C# - Access mobile phone files C#:如何判断碰撞发生在哪一侧? - C#: How can I tell which side a collision has occured on?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM