void FindNetworks() { Dictionary <string, List <Tuple <Wlan.WlanAvailableNetwork, WlanClient.WlanInterface> > > hashedNetworks = new Dictionary <string, List <Tuple <Wlan.WlanAvailableNetwork, WlanClient.WlanInterface> > >(); foreach (WlanClient.WlanInterface wlanIface in WlanClient.Instance.Interfaces) { try { Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0); foreach (Wlan.WlanAvailableNetwork network in networks) { string ssid = Helper.GetStringForSSID(network.dot11Ssid); if (!string.IsNullOrEmpty(ssid)) { List <Tuple <Wlan.WlanAvailableNetwork, WlanClient.WlanInterface> > networksForSSID; if (!hashedNetworks.TryGetValue(ssid, out networksForSSID)) { hashedNetworks[ssid] = networksForSSID = new List <Tuple <Wlan.WlanAvailableNetwork, WlanClient.WlanInterface> >(); } networksForSSID.Add(new Tuple <Wlan.WlanAvailableNetwork, WlanClient.WlanInterface>(network, wlanIface)); } } } catch { // the network interface might be disabled - wrapper throws an exception in that case when getting the available networks } } Networks.Clear(); foreach (var ssidNetwork in hashedNetworks.OrderByDescending(hn => hn.Value.Max(n => n.Item1.wlanSignalQuality))) { var networkInfo = ssidNetwork.Value.OrderByDescending(n => n.Item1.wlanSignalQuality).First(); var network = networkInfo.Item1; if (network.networkConnectable) { string readableSSID = Helper.GetStringForSSID(network.dot11Ssid); if (string.IsNullOrWhiteSpace(readableSSID)) { readableSSID = "No SSID"; } ListItem item = new ListItem(Consts.KEY_NAME, readableSSID, false); item.Selected = (network.flags & Wlan.WlanAvailableNetworkFlags.Connected) == Wlan.WlanAvailableNetworkFlags.Connected; item.AdditionalProperties["SignalStrength"] = network.wlanSignalQuality / 100.0f; item.AdditionalProperties["Secure"] = network.securityEnabled; item.AdditionalProperties["HasProfile"] = (network.flags & Wlan.WlanAvailableNetworkFlags.HasProfile) == Wlan.WlanAvailableNetworkFlags.HasProfile; item.AdditionalProperties["Network"] = network; item.AdditionalProperties["Interface"] = networkInfo.Item2; Networks.Add(item); } } Networks.FireChange(); }
public async Task ScanAsync() { if (WiFiAdapter != null) { await WiFiAdapter.ScanAsync(); ScanTimestamp = WiFiAdapter.NetworkReport.Timestamp.ToString("MM-dd hh:mm:ss"); Networks.Clear(); foreach (var n in WiFiAdapter.NetworkReport.AvailableNetworks) { Networks.Add(n); } } else { throw new InvalidOperationException("Cannot scan WiFi signal without WiFi adapter."); } }