如何重置WLAN信息的系统缓存? [英] How do i reset the system cache of WLAN info?

查看:168
本文介绍了如何重置WLAN信息的系统缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用C#中的NativeWifi编写WLAN指纹识别程序.为此,我运行了一个循环以多次获取无线局域网信息,然后稍后使用matlab对数据进行平均/分析.

I am trying to write a WLAN fingerprinting program using NativeWifi in C#. To do this i run a loop to get the wlan information many times and then later use matlab to average / analyze the data.

问题是,即使程序运行时我四处走动,我也会得到所有相同的值.从互联网上,我已经看到有一个缓存,用于存储可用网络的数据.我想知道是否有系统调用会重置此缓存.

The problem is that i get all the same values, even as i move about the house, when the program is running. From the internet i've seen that there is a cache that stores the data of available networks. I was wondering if there is a system call which resets this cache.

我也通过cmd调用看到了这一点

I have also seen this using the cmd call

netsh wlan show networks mode = bssid

netsh wlan show networks mode=bssid

这将为我提供相同的值,直到我在操作系统中打开可用的wifi网络为止,如果此后再次运行它,它将提供不同的值.

this gives me the same values until i open the available wifi networks in my OS and if i run it again after, it will give different values.

edit:该系统仅供我使用,因此,如果有已知的库可以为我处理,那么我将在Linux平台上重新开始.不过,我什至不知道要用Google来获取什么信息.与网络缓存"相关的任何事情都需要我来帮助无关主题的话题...

edit: This system will be for my use only, so i would be comfortable starting over on a linux platform if there is a known library that can handle this for me. I don't even know what to google to even get the information, though. Anything related to "network cache" takes me to help threads of unrelated topics...

我将在下面提供我代码的相关部分:

I will provide the relevant part of my code below:

        public void get_info_instance(StreamWriter file)
        {
                try
                {
                    foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
                    {

                        Wlan.WlanBssEntry[] wlanBssEntries = wlanIface.GetNetworkBssList();

                        foreach (Wlan.WlanBssEntry network in wlanBssEntries)
                        {
                            int rss = network.rssi;
                            byte[] macAddr = network.dot11Bssid;
                            string tMac = "";
                            for (int i = 0; i < macAddr.Length; i++)
                            {
                                tMac += macAddr[i].ToString("x2").PadLeft(2, '0').ToUpper();
                            }


                            file.WriteLine("Found network: " + System.Text.ASCIIEncoding.ASCII.GetString(network.dot11Ssid.SSID).ToString());
                            file.WriteLine("Signal: " + network.linkQuality + "%");
                            file.WriteLine("BSS Type: " + network.dot11BssType + ".");
                            file.WriteLine("RSSID: " + rss.ToString());
                            file.WriteLine("BSSID: " + tMac);
                            file.WriteLine(" ");
                        }
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                } 
        }

推荐答案

在内部,netsh由

Internally, netsh is powered by this API. What this means, is that calling netsh wlan show networks mode=bssid just returns the cache of the networks that showed up during the last scan. This is what you've discovered.

这意味着要刷新此缓存,您需要触发扫描.如果您正在使用的C#库包含它,则可以通过调用扫描完整的通知(向源WLAN_NOTIFICATION_SOURCE_ACM注册并注意wlan_notification_acm_scan_list_refresh),应该更新缓存.

This means that in order to refresh this cache, you need to trigger a scan. If your C# library you are using includes it, you could make this happen on demand with a call to WlanScan. I am not sure which C# wrapper you are using, but it probably includes this function. When you get a scan complete notification (register with source WLAN_NOTIFICATION_SOURCE_ACM and look out for wlan_notification_acm_scan_list_refresh), the cache should be updated.

如果您让我知道您正在使用哪个C#库,也许我可以为您提供相关功能.

If you let me know which C# library you are using, maybe I can point you to the relevant functions.

您提到打开可用网络会导致缓存刷新.这是因为打开可用网络会触发对WlanScan的呼叫.

You mentioned that opening the available networks causes the cache to refresh. This is because opening the available networks triggers a call to WlanScan.

配置文件与可用的网络列表无关-配置文件是Wlan服务用来跟踪计算机上配置的网络的配置文件-删除它们不会使WlanSvc再次扫描.删除它们恰巧与扫描同时发生,这可能是一个巧合,但比设计用途更多的是副作用.

Profiles are not relevant to the available network list -- profiles are what the Wlan service uses to keep track of which networks are configured on your machine -- deleting them does not make WlanSvc scan again. It may be a coincidence that deleting them happens to coincide with a scan, but it is more of a side effect than the designed usage.

要使用您使用的Managed Wifi API订阅通知,此代码段应该起作用:

edit: to subscribe to notifications using the Managed Wifi API you are using, this snippet should work:

    wlanIface.WlanNotification += wlanIface_WlanNotification;

和回调:

    static void wlanIface_WlanNotification(Wlan.WlanNotificationData notifyData)
    {
        if (notifyData.notificationCode == (int)Wlan.WlanNotificationCodeAcm.ScanComplete)
        {
            Console.WriteLine("Scan Complete!");
        }
    }

您可以通过运行此程序,然后在Windows上打开可用的网络来对其进行测试.每次打开后不久,您应该会看到扫描完成".如果愿意,可以使用消息框代替Console.WriteLine.

You can test this by running this, then opening the available networks on Windows. You should see "Scan Complete" shortly after you open it each time. You can use a messagebox instead of Console.WriteLine if you prefer.

要自己触发扫描:

    wlanIface.Scan();

这篇关于如何重置WLAN信息的系统缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆