public IEnumerable <NetworkData> GetNetworkData() { List <NetworkData> list = new List <NetworkData>(); IEnumerable <NdisWlanBssidEx> exArray = Ndis.QueryBssidList(_interface); //Gets the connected AP BSSID byte[] connectedBssid = Ndis.QueryConnected(_interface); if (exArray != null) { foreach (NdisWlanBssidEx ex in exArray) { NetworkData data2 = new NetworkData(ex.MacAddress); data2.Channel = Utilities.ConvertToChannel(ex.Configuration.DSConfig); NetworkData item = data2; if (item.MyMacAddress.MyValue == 0) { continue; } if ((ex.IELength <= ex.IEs.Length) && (ex.IELength > 28)) { byte[] ies = new byte[ex.IELength]; Array.Copy(ex.IEs, 0, ies, 0, ex.IELength); item.NSettings = IeParser.Parse(ies); item.IsTypeN = item.NSettings != null; if (item.NSettings != null) { //Add the extended 802.11N rates item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f))); item.Rates.Sort(); } //} } Utilities.ConvertToMbs(ex.SupportedRates, item.Rates, item.IsTypeN); item.Rssi = ex.Rssi; item.SignalQuality = 0; string str = Encoding.ASCII.GetString(ex.Ssid, 0, (int)ex.SsidLength); if (str != null) { str = str.Trim(); } item.Ssid = str; item.Security = Ndis.GetSecurityString(ex); item.NetworkType = Utilities.FindValueString(Utilities.InfrastructureText, (int)ex.InfrastructureMode); //Check to see if this AP is the connected one item.Connected = item.MyMacAddress.Bytes.SequenceEqual(connectedBssid); list.Add(item); } } return(list); }
private IEnumerable <NetworkData> GetXpNetworkData() { List <NetworkData> list = new List <NetworkData>(); IEnumerable <NdisWlanBssidEx> exArray = MyNdis.QueryBssidList(MyWlanInterface.NetworkInterface); if (exArray != null) { foreach (NdisWlanBssidEx ex in exArray) { NetworkData data2 = new NetworkData(ex.MacAddress); data2.Channel = Utilities.ConvertToChannel(ex.Configuration.DSConfig); NetworkData item = data2; if ((ex.IELength <= ex.IEs.Length) && (ex.IELength > 28)) { bool foundNIes = false; for (int i = 0; i < (ex.IELength /* - 29*/); i++) { if (((ex.IEs[i] == 0x2D) && (ex.IEs[i + 1] == 26)) && ((ex.IEs[i + 28] == 0x3D) && (ex.IEs[(i + 28) + 1] == 0x16))) { foundNIes = true; break; } } if (foundNIes) { item.IsTypeN = true; item.NSettings = IeParser.Parse(ex.IEs); //item.Rates.Add(IEParser.MCSSet.GetSpeed(item.NSettings.maxMCS, item.NSettings.ShortGI20MHz, // item.NSettings.ShortGI40MHz, item.NSettings.Is40MHz)); //Add the extended 802.11N rates item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f))); item.Rates.Sort(); } } Utilities.ConvertToMbs(ex.SupportedRates, item.Rates, item.IsTypeN); item.Rssi = ex.Rssi; item.SignalQuality = 0; string str = Encoding.ASCII.GetString(ex.Ssid, 0, (int)ex.SsidLength); if (str != null) { str = str.Trim(); } item.Ssid = str; item.Privacy = MyNdis.GetPrivacyString(ex); item.NetworkType = Utilities.FindValueString(Utilities.NetworkTypeText, (int)ex.NetworkTypeInUse); list.Add(item); } } return(list); }
public IEnumerable <NetworkData> GetNetworkData() { List <NetworkData> list = new List <NetworkData>(); //If the interface is null, return nothing if (_interface == null) { return(list); } IEnumerable <Wlan.WlanBssEntryN> networkBssList = null; IEnumerable <Wlan.WlanAvailableNetwork> availableNetworkList = null; try { networkBssList = _interface.GetNetworkBssList(); availableNetworkList = _interface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllManualHiddenProfiles); } catch (NullReferenceException) { //Hopefully the call will succeed next time. } if ((networkBssList != null) && (availableNetworkList != null)) { //Get connected to AP Wlan.WlanAssociationAttributes connectedAP = new Wlan.WlanAssociationAttributes(); try { if (_interface.CurrentConnection.isState == Wlan.WlanInterfaceState.Connected) { connectedAP = _interface.CurrentConnection.wlanAssociationAttributes; } } catch (NullReferenceException) { /*Hopefully it will work next time*/ } Wlan.WlanAvailableNetwork foundNetwork = new Wlan.WlanAvailableNetwork(); foreach (Wlan.WlanBssEntryN entry in networkBssList) { string ssid = Encoding.ASCII.GetString(entry.BaseEntry.dot11Ssid.SSID, 0, (int)entry.BaseEntry.dot11Ssid.SSIDLength); if (FindNetwork(ssid, availableNetworkList, ref foundNetwork)) { NetworkData item = new NetworkData(entry.BaseEntry.dot11Bssid); item.IsTypeN = (entry.BaseEntry.dot11BssPhyType == Wlan.Dot11PhyType.Ht); if (item.IsTypeN && entry.IEs != null && entry.IEs.Length > 0) { item.NSettings = IeParser.Parse(entry.IEs); if (item.NSettings == null) { return(null); } //Add the extended 802.11N rates item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f))); item.Rates.Sort(); } Utilities.ConvertToMbs(entry.BaseEntry.wlanRateSet.Rates, item.Rates); item.IsTypeN = entry.BaseEntry.dot11BssPhyType == Wlan.Dot11PhyType.Ht; int num = Utilities.ComputeRssi(entry.BaseEntry.linkQuality); item.Rssi = (entry.BaseEntry.rssi > num) ? entry.BaseEntry.rssi : num; // tyler's fix // Sometimes there is an issue where the RSSI will become overly positive // (e.g. going from -96 to +160), so subtracting 256 will fix it. if (item.Rssi > 0) { item.Rssi -= 256; } item.Ssid = ssid; item.Channel = Utilities.ConvertToChannel(entry.BaseEntry.chCenterFrequency); item.NetworkType = Utilities.ConvertToString(entry.BaseEntry.dot11BssType); item.Security = Utilities.CreateSecurityString(foundNetwork.dot11DefaultAuthAlgorithm, foundNetwork.dot11DefaultCipherAlgorithm); item.SignalQuality = foundNetwork.wlanSignalQuality; //Check to see if this AP is the connected one item.Connected = item.MyMacAddress.CompareToPhysicalAddress(connectedAP.Dot11Bssid); list.Add(item); } } } return(list); }