C#仅从具有托管Wifi api的活动Wifi网络读取Bssid

时间:2019-02-06 09:28:11

标签: c# .net

我是C#的新手。我正在寻找一种解决方案,即我想从活动的WiFi连接中读取BSSID。我在网络上找到了代码,但是它从所有可用的WiFi网络返回BSSID。我只想通过有效的连接获取BSSID。如果有人能帮助我,我将不胜感激。我使用https://archive.codeplex.com/?p=managedwifi

中的库
textBox1.Text = "";
                textBox2.Text = "";

                var wlanClient = new WlanClient();
                foreach (WlanClient.WlanInterface wlanInterface in wlanClient.Interfaces)
                {
                    Wlan.WlanBssEntry[] wlanBssEntries = wlanInterface.GetNetworkBssList();
                    foreach (Wlan.WlanBssEntry wlanBssEntry in wlanBssEntries)
                    {
                        byte[] macAddr = wlanBssEntry.dot11Bssid;
                        Wlan.Dot11Ssid ssid = wlanBssEntry.dot11Ssid;
                        string networkName = Encoding.ASCII.GetString(ssid.SSID, 0, (int)ssid.SSIDLength);
                        MessageBox.Show(networkName);
                        var macAddrLen = (uint)macAddr.Length; var str = new string[(int)macAddrLen];
                        for (int i = 0; i < macAddrLen; i++)
                        {
                            str[i] = macAddr[i].ToString("x2");
                        }
                        string mac = string.Join(":", str);
                        string ident = string.Join("", str);

                        ident = ident.Substring(8);
                        textBox1.Text = ident.ToUpper();
                        textBox2.Text = mac.ToUpper();

                    }
                }

0 个答案:

没有答案