コード例 #1
0
        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);

                        Utilities.ConvertToMbs(entry.BaseEntry.wlanRateSet.Rates, item.Rates);
                        if (entry.NSettings != null)
                        {
                            item.NSettings = new IeParser.TypeNSettings(entry.NSettings);

                            //Add the extended 802.11N rates
                            item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f)));
                            item.Rates.Sort();
                        }

                        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;
                        if (item.Rssi > 0)
                            item.Rssi -= 256; // Sometimes there is an issure where the RSSI will become overly positive
                                              // (e.g. going from -96 to +160), so subtracting 256 will fix it.
                        item.Ssid = ssid;
                        item.Channel = Utilities.ConvertToChannel(entry.BaseEntry.chCenterFrequency);
                        item.NetworkType = Utilities.ConvertToString(entry.BaseEntry.dot11BssType);

                        if (foundNetwork.numberOfBssids > 1)
                        {
                            // More than 1 network with the same SSID
                            // Get all BSSes with the SSID
                            Wlan.WlanBssEntryN[] secureNetworks = _interface.GetNetworkBssList(ssid, true);
                            Wlan.WlanBssEntryN[] openNetworks = _interface.GetNetworkBssList(ssid, false);
                            if (secureNetworks.Count(bss => bss.BaseEntry.dot11Bssid.SequenceEqual(item.MyMacAddress.Bytes)) > 0)
                            {
                                item.Privacy = _interface.GetPrivacyString(secureNetworks.First(bss => bss.BaseEntry.dot11Bssid.SequenceEqual(item.MyMacAddress.Bytes)).IEs, true);
                            }
                            else if (openNetworks.Count(bss => bss.BaseEntry.dot11Bssid.SequenceEqual(item.MyMacAddress.Bytes)) > 0)
                            {
                                item.Privacy = "None";
                            }
                        }
                        else
                        {
                            item.Privacy = Utilities.CreatePrivacyString(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;
        }
コード例 #2
0
        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);

                        Utilities.ConvertToMbs(entry.BaseEntry.wlanRateSet.Rates, item.Rates);
                        if (entry.NSettings != null)
                        {
                            item.NSettings = new IeParser.TypeNSettings(entry.NSettings);

                            //Add the extended 802.11N rates
                            item.Rates.AddRange(item.NSettings.Rates.Where(f => !item.Rates.Contains(f)));
                            item.Rates.Sort();
                        }

                        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;
                        item.Ssid = ssid;
                        item.Channel = Utilities.ConvertToChannel(entry.BaseEntry.chCenterFrequency);
                        item.NetworkType = Utilities.ConvertToString(entry.BaseEntry.dot11BssType);
                        item.Privacy = Utilities.CreatePrivacyString(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;
        }