/// <summary> /// Enumerates SSIDs of connected wireless LANs. /// </summary> /// <returns>SSIDs</returns> public static IEnumerable <NetworkIdentifier> EnumerateConnectedNetworkSsids() { using (var client = new Base.WlanClient()) { var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle); foreach (var interfaceInfo in interfaceInfoList) { var connection = Base.GetConnectionAttributes(client.Handle, interfaceInfo.InterfaceGuid); if (connection.isState != WLAN_INTERFACE_STATE.wlan_interface_state_connected) { continue; } var association = connection.wlanAssociationAttributes; //Debug.WriteLine("Interface: {0}, SSID: {1}, BSSID: {2}, Signal: {3}", // interfaceInfo.strInterfaceDescription, // association.dot11Ssid, // association.dot11Bssid, // association.wlanSignalQuality); yield return(new NetworkIdentifier(association.dot11Ssid.ToBytes(), association.dot11Ssid.ToString())); } } }
/// <summary> /// Enumerates wireless profile information in preference order. /// </summary> /// <returns>Wireless profile information</returns> public static IEnumerable <ProfilePack> EnumerateProfiles() { using (var client = new Base.WlanClient()) { var interfaceInfoList = Base.GetInterfaceInfoList(client.Handle); foreach (var interfaceInfo in interfaceInfoList.Select(x => ConvertToInterfaceInfo(x))) { var interfaceIsConnected = (interfaceInfo.State == InterfaceState.Connected); var availableNetworkList = Base.GetAvailableNetworkList(client.Handle, interfaceInfo.Id) .Where(x => !string.IsNullOrWhiteSpace(x.strProfileName)) .ToArray(); var connection = Base.GetConnectionAttributes(client.Handle, interfaceInfo.Id); var profileInfoList = Base.GetProfileInfoList(client.Handle, interfaceInfo.Id); int position = 0; foreach (var profileInfo in profileInfoList) { var availableNetwork = availableNetworkList.FirstOrDefault(x => x.strProfileName.Equals(profileInfo.strProfileName, StringComparison.Ordinal)); var signalQuality = (int)availableNetwork.wlanSignalQuality; var profileIsConnected = interfaceIsConnected && profileInfo.strProfileName.Equals(connection.strProfileName, StringComparison.Ordinal); //Debug.WriteLine("Interface: {0}, Profile: {1}, Signal {2}, Position: {3}, Connected {4}", // interfaceInfo.Description, // profileInfo.strProfileName, // signalQuality, // position, // profileIsConnected); var profile = GetProfile( client.Handle, interfaceInfo, profileInfo.strProfileName, signalQuality, position++, profileIsConnected); if (profile != null) { yield return(profile); } } } } }