private static void NotifyCurrentStatus(ConnectionProfile p) { if (p == null) { Debug.WriteLine("No service."); InvokeNotification("No service."); return; } if (p.IsWwanConnectionProfile) { Debug.WriteLine("Current: WWan"); var sb = new StringBuilder(); sb.AppendLine("WWan: " + p.GetNetworkNames().Aggregate((a, b) => a + " " + b)); if (p.GetSignalBars() != null) { sb.AppendLine("Level: " + p.GetSignalBars().Value); } var detail = p.WwanConnectionProfileDetails; if (detail != null) { sb.AppendLine("APN: " + detail.AccessPointName); sb.AppendLine("IPKind: " + detail.IPKind); sb.AppendLine("Registration state: " + detail.GetNetworkRegistrationState().ToString()); sb.AppendLine("Connection type: " + detail.GetCurrentDataClass().ToString()); } InvokeNotification(sb.ToString()); } else if (p.IsWlanConnectionProfile) { Debug.WriteLine("Current: WLan"); var sb = new StringBuilder(); sb.Append("WLan: " + p.ProfileName); sb.Append(" "); sb.Append(p.GetNetworkNames().Aggregate((a, b) => a + " " + b)); sb.Append(" Level: "); if (p.GetSignalBars() != null) { sb.Append(p.GetSignalBars().Value); } InvokeNotification(sb.ToString()); } else { Debug.WriteLine("No service."); InvokeNotification("No service."); } }
//Get network connection name internal static async Task <string> GetNetworkName() { try { //Check connection ConnectionProfile ConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); if (ConnectionProfile == null) { return("No connection"); } else { //Get Wi-Fi / Ethernet name string FirstNetwork = ConnectionProfile.GetNetworkNames().FirstOrDefault(); if (!string.IsNullOrWhiteSpace(FirstNetwork)) { return(FirstNetwork); } //Get Cellular name if (ConnectionProfile.IsWwanConnectionProfile) { PhoneCallStore phoneCallStore = await PhoneCallManager.RequestStoreAsync(); PhoneLine phoneLine = await PhoneLine.FromIdAsync(await phoneCallStore.GetDefaultLineAsync()); return(phoneLine.NetworkName); } return("Unknown"); } } catch { return("Unknown"); } }
public static string GetNetWorkName() { bool isConnected = false; string InternetType = null; ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile(); if (profile == null) { InternetType = InternetStatus.None; } else { NetworkConnectivityLevel cl = profile.GetNetworkConnectivityLevel(); isConnected = (cl != NetworkConnectivityLevel.None); } if (!isConnected) { return(InternetStatus.None); } else if (profile.IsWlanConnectionProfile) { profile.GetNetworkNames(); InternetType = profile.ProfileName.ToString(); } else { InternetType = InternetStatus.Lan; } return(InternetType); }
/// <summary> /// Retrieve SSID of connected wifi network /// </summary> /// <param name="wiFiAdapter"></param> /// <returns>String - SSID</returns> private static async Task <String> getConnectedWifi(WiFiAdapter wiFiAdapter) { await wiFiAdapter.ScanAsync(); ConnectionProfile connectedProfile = await wiFiAdapter.NetworkAdapter.GetConnectedProfileAsync(); return(connectedProfile.GetNetworkNames()[0]); }
/// <summary> /// Updates the current object based on profile passed. /// </summary> /// <param name="profile">instance of <see cref="ConnectionProfile"/></param> public virtual void UpdateConnectionInformation(ConnectionProfile profile) { networkNames.Clear(); if (profile == null) { ConnectionType = ConnectionType.Unknown; ConnectivityLevel = NetworkConnectivityLevel.None; IsInternetAvailable = false; ConnectionCost = null; SignalStrength = null; return; } switch (profile.NetworkAdapter.IanaInterfaceType) { case 6: ConnectionType = ConnectionType.Ethernet; break; case 71: ConnectionType = ConnectionType.WiFi; break; case 243: case 244: ConnectionType = ConnectionType.Data; break; default: ConnectionType = ConnectionType.Unknown; break; } ConnectivityLevel = profile.GetNetworkConnectivityLevel(); ConnectionCost = profile.GetConnectionCost(); SignalStrength = profile.GetSignalBars(); var names = profile.GetNetworkNames(); if (names?.Count > 0) { networkNames.AddRange(names); } switch (ConnectivityLevel) { case NetworkConnectivityLevel.None: case NetworkConnectivityLevel.LocalAccess: IsInternetAvailable = false; break; default: IsInternetAvailable = true; break; } }
void RefreshNetwork() { ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile(); StringBuilder str = new StringBuilder(); if (profile != null) { str.Append("Network Name: "); str.Append(profile.GetNetworkNames()[0]); str.Append("Network Type: "); str.Append(profile.GetNetworkConnectivityLevel()); } else { str.Append("Disconnected"); } networkInformatin.Text = str.ToString(); }
/// <summary> /// 获取网络运营商信息 /// </summary> /// <returns></returns> public static string GetNetworkName() { try { ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile(); if (profile != null) { if (profile.IsWwanConnectionProfile) { var name = profile.GetNetworkNames().FirstOrDefault(); if (name != null) { name = name.ToUpper(); if (name == "CMCC") { return("中国移动"); } else if (name == "UNICOM") { return("中国联通"); } else if (name == "TELECOM") { return("中国电信"); } } return("其他"); } else { return("其他"); } } return("其他"); } catch (Exception ex) { Debug.WriteLine(ex); return("其他"); } }