Exemple #1
0
        /// <summary>
        /// Get known profile names from specified interface.
        /// </summary>
        /// <param name="wlanIface"></param>
        /// <returns></returns>
        public List <string> GetKnownProfileNames(WlanInterface wlanIface)
        {
            List <string> profiles = new List <string>();

            if (_client.NoWifiAvailable)
            {
                return(null);
            }

            WlanProfileInfo[] rawProfileInfo = wlanIface.GetProfiles();

            foreach (WlanProfileInfo profileInfo in rawProfileInfo)
            {
                bool anotherInstanceWithProfileExists =
                    rawProfileInfo.Any(n => n.Equals(profileInfo) && !string.IsNullOrEmpty(n.profileName));

                if (!anotherInstanceWithProfileExists)
                {
                    profiles.Add(profileInfo.profileName);
                }
            }

            return(profiles);
        }
Exemple #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                if (checkBox1.Checked)
                {
                    listView1.Items.Clear();
                    if (listBox1.SelectedItem != null)
                    {
                        WlanInterface wlanIface = client.Interfaces.Where(s => s.InterfaceDescription.Equals(listBox1.SelectedItem.ToString())).First();
                        try
                        {
                            if (wlanIface.InterfaceState == WlanInterfaceState.Connected)
                            {
                                connectedSSID   = wlanIface.CurrentConnection.profileName;
                                label1.Text     = "Current connection: " + connectedSSID + " " + wlanIface.CurrentConnection.isState;
                                button3.Enabled = true;
                            }
                            else
                            {
                                connectedSSID   = string.Empty;
                                label1.Text     = "Current connection: " + wlanIface.InterfaceState;
                                button3.Enabled = false;
                            }
                        }
                        catch {
                            connectedSSID   = string.Empty;
                            label1.Text     = "Current connection: " + wlanIface.InterfaceState;
                            button3.Enabled = false;
                        }

                        wlanIface.Scan();

                        WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(WlanGetAvailableNetworkFlags.IncludeAllAdhocProfiles);
                        foreach (WlanAvailableNetwork network in networks.GroupBy(x => GetStringForSSID(x.dot11Ssid)).Select(y => y.First()).OrderByDescending(r => r.wlanSignalQuality))
                        {
                            ListViewItem li = new ListViewItem();
                            li.Text = GetStringForSSID(network.dot11Ssid);
                            li.SubItems.Add(network.networkConnectable.ToString());
                            li.SubItems.Add(network.wlanSignalQuality.ToString());
                            li.SubItems.Add(network.dot11DefaultCipherAlgorithm.ToString());
                            li.SubItems.Add(network.dot11DefaultAuthAlgorithm.ToString());
                            li.SubItems.Add(network.securityEnabled.ToString());

                            try
                            {
                                WlanProfileInfo[] wpi = wlanIface.GetProfiles().Where(s => s.profileName.Equals(li.Text)).ToArray();
                                li.Tag = (wpi.Length > 0 && wlanIface.InterfaceState != WlanInterfaceState.Connected) ? "true" : "false";
                            }
                            catch {
                                li.Tag = "false";
                            }


                            if (selectedSSID == li.Text)
                            {
                                li.Selected = true;
                                if (li.Tag.ToString() == "true")
                                {
                                    button2.Enabled = true;
                                }
                                else
                                {
                                    button2.Enabled = false;
                                }
                            }

                            if (connectedSSID == li.Text)
                            {
                                li.ForeColor = Color.White;
                                li.BackColor = Color.Green;
                            }
                            else
                            {
                                li.ForeColor = Color.Black;
                                li.BackColor = Color.LightCyan;
                            }
                            listView1.Items.Add(li);
                        }
                    }

                    /*foreach (AccessPoint ap in wifi.GetAccessPoints())
                     * {
                     *  ListViewItem li = new ListViewItem();
                     *  li.Text = ap.Name;
                     *  li.SubItems.Add(ap.SignalStrength.ToString());
                     *  li.SubItems.Add(ap.Interface.Channel.ToString());
                     *  li.SubItems.Add(ap.HasProfile.ToString());
                     *  li.SubItems.Add(ap.IsConnected.ToString());
                     *  li.SubItems.Add(ap.IsSecure.ToString());
                     *  if (selectedSSID == li.Text)
                     *  {
                     *      li.Selected = true;
                     *  }
                     *  if (connectedSSID == li.Text)
                     *  {
                     *      li.ForeColor = Color.White;
                     *      li.BackColor = Color.Green;
                     *  }
                     *  else
                     *  {
                     *      li.ForeColor = Color.Black;
                     *      li.BackColor = Color.LightCyan;
                     *  }
                     *  listView1.Items.Add(li);
                     * }*/
                }
            }
            catch
            {
            }
        }