当前位置:编程学习 > C#/ASP.NET >>

求助 wifi 信号加快搜索方法

大家好,我在此感谢goodsoft大哥昨天的帮忙。

之前我在这里问过大家 关于拿wifi 的mac地址和信号强度的问题,后来找到了解决的方法,代码如下,但是想要改进一下,希望大家帮个忙。

因为每次按下按键才会扫描一次周边的wifi信号,想要在多扫描一次要等40秒左右,这样有点太慢了,大家有没有什么办法可以一直监听 想要的mac的信号,或者快点扫描的方法,谢谢大家,下面代码完全可用,有需要的朋友拿去用吧。代码引用了ManagedWifi.dll。

private void btnWifiList_Click(object sender, EventArgs e)
        {
            try
            {
                Json = @"WiFi Signals has been collected: ";
                lstWifi.Items.Clear();

                WlanClient wLanClient = new NativeWifi.WlanClient();
                if (wLanClient.Inte易做图ces.Length == 0)
                {
                    MessageBox.Show("No Wifi Inte易做图ces found, Please check the device");
                    return;
                }
                Wlan.WlanBssEntry[] lstWlanBss = wLanClient.Inte易做图ces[0].GetNetworkBssList();
                if (lstWlanBss == null)
                {
                    MessageBox.Show("No networks has been detected.");
                    return;
                }
                System.Text.StringBuilder SB = new StringBuilder();
               
                foreach (var oWlan in lstWlanBss)
                {
                    ListViewItem lstItem = lstWifi.Items.Add(System.Text.Encoding.UTF8.GetString(oWlan.dot11Ssid.SSID));

                    lstItem.SubItems.Add(CalculateSignalQuality(oWlan.linkQuality).ToString());
                    string MAC = ConvertToMAC(oWlan.dot11Bssid);
                    lstItem.SubItems.Add(MAC);
                    
                    SB.Append(System.Environment.NewLine);
                    SB.Append(@"{""MAC"" :""");
                    SB.Append(MAC);
                    SB.Append(@"""");
                    SB.Append(@", ""Strength"" :");
                    SB.Append(CalculateSignalQuality(oWlan.linkQuality).ToString());
                    SB.Append(@", ""SSID"" : """);
                    string SSID = System.Text.Encoding.UTF8.GetString(oWlan.dot11Ssid.SSID, 0, (int)oWlan.dot11Ssid.SSIDLength);
                    if ((SSID.Length == 0) || SSID[0]==0) SSID = "NA";                    
                    SB.Append(SSID);
                    SB.Append(@""" },");
                 }
                 
                txtFiltered.Text = "";
             
                foreach (var oWlan in lstWlanBss)
                {
                 
                    string MAC = ConvertToMAC(oWlan.dot11Bssid);
                    if (MAC == "64-70-02-55-39-88")
                    {
                        AP1 = CalculateSignalQuality(oWlan.linkQuality);

                        txtFiltered.Text = txtFiltered.Text + MAC + "  //  Signal Strength: " + AP1 + "  //  AP 1" + "\r\n";

                    }

                    if (MAC == "A0-F3-C1-72-66-06")
                    {
                        AP2 = CalculateSignalQuality(oWlan.linkQuality);

                        txtFiltered.Text = txtFiltered.Text + MAC + "  //  Signal Strength: " + AP2 + "  //  AP 2" + "\r\n";

                    }

                    if (MAC == "A0-F3-C1-72-65-E6")
                    {
                        AP3 = CalculateSignalQuality(oWlan.linkQuality);

                        txtFiltered.Text = txtFiltered.Text + MAC + "  //  Signal Strength: " + AP3 + "  //  AP 3" +  "\r\n";

                    }

                    if (MAC == "A0-F3-C1-72-8A-52")
                    {
                        AP4 = CalculateSignalQuality(oWlan.linkQuality);

                        txtFiltered.Text = txtFiltered.Text + MAC + "  //  Signal Strength: " + AP4 + "  //  AP 4 " + "\r\n";

                    }
                 
                    
                }
               
                Json += SB.ToString().Substring(0, SB.Length - 1); // copy all except last ","
                Json += "]}";
 
                textSignals.Text = Json;
              
            }
            catch
            {
                MessageBox.Show("Could not retrieve Wifi information.");
            }

        }
--------------------编程问答-------------------- 不懂觉得厉害。。学习 --------------------编程问答-------------------- 大家帮帮忙啊 --------------------编程问答-------------------- 完全不懂 --------------------编程问答-------------------- if (MAC == "A0-F3-C1-72-8A-52")
                     {
                         AP4 = CalculateSignalQuality(oWlan.linkQuality);
 
                        txtFiltered.Text = txtFiltered.Text + MAC + "  //  Signal Strength: " + AP4 + "  //  AP 4 " + "\r\n";
 
                    }
                   --------------------编程问答-------------------- 您的代码不全啊
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,