public IList<WiFiConnectedSensor> GetAllWiFiConnectedSensorData() { IList<WiFiConnectedSensor> sensors = new List<WiFiConnectedSensor>(); try { using (var wifiApi = new JimbeWiFi(_version)) { logger.Debug("Getting wlan interfaces list"); var interfaceslist = wifiApi.WiFiEnumInterfaces(); foreach (WifiInterface wifiInterface in interfaceslist.Where(x => x.IsState==WifiInterface.WlanInterfaceState.connected)) { logger.Debug("Getting current connected network ", wifiInterface.InterfaceGuid, " ", wifiInterface.Description); var wiFiConnectedSensor = new WiFiConnectedSensor() { HistorySize = 5, Weigth = ConnectedWeigth }; try { var network = wifiApi.WiFiGetCurrentConnection(wifiInterface); var wiFiNetworkSet = new WiFiNetworkSet() { Sensor = wiFiConnectedSensor }; IList<WiFiNetwork> networks = new List<WiFiNetwork>(); networks.Add(new WiFiNetwork(network.Ssid, network.SignalQuality, wiFiNetworkSet)); wiFiNetworkSet.Networks = networks; wiFiConnectedSensor.Datasets.Add(wiFiNetworkSet); sensors.Add(wiFiConnectedSensor); } catch (WifiException we) { logger.Error("Error in getting Network 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; }
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); } } }