private void LoadNetWork() { System.Int32 dwFlag = new Int32(); Wlan.WlanAvailableNetwork[] networks = WlanIface.GetAvailableNetworkList(0); foreach (Wlan.WlanAvailableNetwork network in networks) { string SSID = WlanHelper.GetStringForSSID(network.dot11Ssid); if (network.flags.HasFlag(Wlan.WlanAvailableNetworkFlags.Connected)) { labelControl2.Text = SSID; } //如果有配置文件的SSID会重复出现。过滤掉 if (!myListBox1.Items.Contains(SSID)) { myListBox1.Items.Add(SSID); NetWorkList.Add(network); } } //信号强度排序 NetWorkList.Sort(delegate(Wlan.WlanAvailableNetwork a, Wlan.WlanAvailableNetwork b) { return(b.wlanSignalQuality.CompareTo(a.wlanSignalQuality)); }); myListBox1.Items.Clear(); foreach (Wlan.WlanAvailableNetwork network in NetWorkList) { myListBox1.Items.Add(WlanHelper.GetStringForSSID(network.dot11Ssid)); } }
//连接 private void txButton1_Click(object sender, EventArgs e) { if (InternetGetConnectedState(out dwFlag, 0)) { ShowToast_InSetup("提示", "网络已连接,请勿重新连接", 2); return; } if (myListBox1.SelectedItems.Count == 0) { return; } if (myListBox1.SelectedIndex == -1) { return; } Wlan.WlanAvailableNetwork wn = NetWorkList[myListBox1.SelectedIndex]; if (wn.securityEnabled && !WlanHelper.HasProfile(WlanIface, WlanHelper.GetStringForSSID(wn.dot11Ssid))) { Form_Password fp = new Form_Password(); if (fp.ShowDialog() == DialogResult.OK) { string pw = fp.Password; WlanHelper.ConnetWifi(WlanIface, wn, pw); fp.Dispose(); } } else { WlanHelper.ConnetWifi(WlanIface, wn); } }
private void LoadNetWork() { Wlan.WlanAvailableNetwork[] networks = WlanIface.GetAvailableNetworkList(0); if (networks == null) { MessageBox.Show("WIFI服务未开启"); return; } foreach (Wlan.WlanAvailableNetwork network in networks) { //过滤信号强度小于20的网络 if (network.wlanSignalQuality < 20) { continue; } string SSID = WlanHelper.GetStringForSSID(network.dot11Ssid); if (network.flags.HasFlag(Wlan.WlanAvailableNetworkFlags.Connected)) { labelControl2.Text = SSID; labelControl2.ForeColor = Color.RosyBrown; } //如果有配置文件的SSID会重复出现。过滤掉 if (!myListBox1.Items.Contains(SSID)) { myListBox1.Items.Add(SSID); NetWorkList.Add(network); } } //信号强度排序 NetWorkList.Sort(delegate(Wlan.WlanAvailableNetwork a, Wlan.WlanAvailableNetwork b) { return(b.wlanSignalQuality.CompareTo(a.wlanSignalQuality)); }); myListBox1.Items.Clear(); foreach (Wlan.WlanAvailableNetwork network in NetWorkList) { myListBox1.Items.Add(WlanHelper.GetStringForSSID(network.dot11Ssid)); } }
//连接 private void txButton1_Click(object sender, EventArgs e) { if (myListBox1.SelectedIndex == -1) { return; } Wlan.WlanAvailableNetwork wn = NetWorkList[myListBox1.SelectedIndex]; if (wn.securityEnabled && !WlanHelper.HasProfile(WlanIface, WlanHelper.GetStringForSSID(wn.dot11Ssid))) { Form_Password fp = new Form_Password(); if (fp.ShowDialog() == DialogResult.OK) { string pw = fp.Password; WlanHelper.ConnetWifi(WlanIface, wn, pw); fp.Dispose(); } } else { WlanHelper.ConnetWifi(WlanIface, wn); } }
//listbox选择框 private void myListBox1_SelectedIndexChanged(object sender, EventArgs e) { Wlan.WlanAvailableNetwork wn = NetWorkList[myListBox1.SelectedIndex]; toolTip1.SetToolTip(myListBox1, WlanHelper.GetWifiToolTip(wn)); }