Exemplo n.º 1
0
        static void Main(string[] args)
        {
            IEnumerable<WifiInterface> interfacelist;
            IEnumerator<WifiInterface> rator;
            int i=0;
            while (i++ < 100)
            {
                {

                }
                JimbeWiFi wifiApi = null;
                try
                {
                    wifiApi = new JimbeWiFi();
                }
                catch (WifiToManyHandleException)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                using (wifiApi)
                {
                    interfacelist = wifiApi.WiFiEnumInterfaces();
                    rator = interfacelist.GetEnumerator();
                    while (rator.MoveNext())
                    {
                        Console.WriteLine("Interface Description: {0} GUID {1} State {2}", rator.Current.Description,
                                          rator.Current.InterfaceGuid, rator.Current.IsState);
                        IEnumerable<WifiNetwork> networkslist = wifiApi.WiFiGetAvailableNetworkList(rator.Current);
                        foreach (WifiNetwork net in networkslist)
                        {
                            Console.WriteLine("\nNetwork ssid= {0} Profile= {1} SignalPower={2} Network Type= {3} ",
                                              net.Ssid, net.Profile, net.SignalQuality, net.Type);
                            foreach (var macAddrs in net.Bssids)
                                Console.WriteLine("\nMAC address: {0}", macAddrs);
                        }
                        if (rator.Current.IsState == WifiInterface.WlanInterfaceState.connected)
                        {
                            var currentnetwork = wifiApi.WiFiGetCurrentConnection(rator.Current);
                            Console.WriteLine(
                                "\nCurrent Network ssid= {0} Profile= {1} SignalPower={2} Network Type= {3} ",
                                currentnetwork.Ssid, currentnetwork.Profile, currentnetwork.SignalQuality,
                                currentnetwork.Type);
                            foreach (var macAddrs in currentnetwork.Bssids)
                                Console.WriteLine(" MAC address: {0}", macAddrs);
                        }
                    }
                    System.Threading.Thread.Sleep(500);
                }
            }
        }
Exemplo n.º 2
0
        public IList<WiFiSensor> GetAllWiFiSensorData()
        {
            IList<WiFiSensor> sensors = new List<WiFiSensor>();
            try
            {
                using (var wifiApi = new JimbeWiFi(_version))
                {
                    logger.Debug("Getting wlan interfaces list");
                    var interfaceslist = wifiApi.WiFiEnumInterfaces();
                    foreach (WifiInterface wifiInterface in interfaceslist)
                    {
                        var wiFiSensor = new WiFiSensor()
                            {
                                Weigth = NotConnectedWeigth,
                                HistorySize = 10
                            };
                        logger.Debug("Getting wlan networks list from interface ", wifiInterface.InterfaceGuid, " ", wifiInterface.Description);
                        try
                        {
                            var networkslist = wifiApi.WiFiGetAvailableNetworkList(wifiInterface);
                            var wiFiNetworkSet = new WiFiNetworkSet()
                                {
                                    Sensor = wiFiSensor
                                };

                            IList<WiFiNetwork> networks =
                                (from net in networkslist select new WiFiNetwork(net.Ssid, net.SignalQuality,wiFiNetworkSet)).ToList();

                            wiFiNetworkSet.Networks=networks;
                            wiFiSensor.Datasets.Add(wiFiNetworkSet);
                            sensors.Add(wiFiSensor);

                        } catch (WifiException we)
                        {
                            logger.Error("Error in getting networks from wlan Interface: ", wifiInterface.InterfaceGuid," ", wifiInterface.Description," ", we.Message);
                        }
                    }
                }
            }catch( WifiToManyHandleException we)
            {
                logger.Error(we.Message);
            } catch(WifiException we)
            {
                logger.Error(we.Message);
            }
            return sensors;
        }