1

我最近一直在尝试制作一个 Wifi 扫描仪,它可以扫描所有 Wifi AP,以检索它们的 RSSI 值。我一直使用的语言是 C#,我使用 Native Wifi API 来获取值。由于stackoverflow,我已经能够得到这个工作。

问题:我正在尝试使用计时器(每秒一次)扫描所有 AP。然而,当我移动到另一个点时,唯一改变的 RSSI 是我连接的那个。所有其他值保持不变。有什么办法可以让其他 RSSI 值每秒改变一次?

在此先感谢,库尔特

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using NativeWifi;

namespace FormFingerPrint
{
public partial class Form1 : Form
{
    Timer myTimer = new Timer();
    static int timerCount = 1;


    public Form1()
    {
        InitializeComponent();
    }

    public static String GetTimestamp(DateTime value)
    {
        return value.ToString("yyyyMMddHHmmss");
    }

    public void AddItemToList(int id, string wind, string SSID, string BSSID, string rssi, string x, string y, string timeStamp){
        ListViewItem item = new ListViewItem(id.ToString());
        item.SubItems.Add(wind);
        item.SubItems.Add(SSID);
        item.SubItems.Add(BSSID);
        item.SubItems.Add(rssi);
        item.SubItems.Add(x.ToString());
        item.SubItems.Add(y.ToString());
        item.SubItems.Add(timeStamp);
        lstvFingerPrint.Items.Add(item);
    }

    public bool checkInput()
    {
        return (cboWindrichting.SelectedItem != null && txtX.Text != "" && txtY.Text != "");
    }

    private void button1_Click(object sender, EventArgs e)
    {
        myTimer.Tick += new EventHandler(ScanWifi);
        myTimer.Interval = 500;
        myTimer.Start();

    }

    private void btnReset_Click(object sender, EventArgs e)
    {
        lstvFingerPrint.Items.Clear();
    }


    private void ScanWifi(Object myObject,EventArgs myEventArgs){


        if (checkInput() && timerCount <=1000)
        {
            using (WlanClient client = new WlanClient())
            {
                try
                {
                    lstvFingerPrint.Items.Clear();
                    foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
                    {

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



                        foreach (Wlan.WlanBssEntry network in wlanBssEntries)
                        {
                            Console.WriteLine(network.rssi);
                            int id = 1;
                            string SSID = System.Text.ASCIIEncoding.ASCII.GetString(network.dot11Ssid.SSID).ToString();
                            string rss = network.rssi.ToString();
                            string windrichting = cboWindrichting.SelectedItem.ToString();
                            //MessageBox.Show(rss.ToString());
                            string x = txtX.Text.ToString();
                            string y = txtY.Text.ToString();
                            byte[] macAddr = network.dot11Bssid;
                            //Indien frequentie nodig zou zijn
                            //string freq = network.chCenterFrequency.ToString();
                            string tMac = "";

                            for (int i = 0; i < macAddr.Length; i++)
                            {
                                tMac += macAddr[i].ToString("x2").PadLeft(2, '0').ToUpper();
                            }

                            string timeStamp = GetTimestamp(DateTime.Now);
                            if (!(SSID.Contains("TELENETHOMESPOT")))
                            {
                                AddItemToList(id, windrichting, SSID, tMac, rss, x, y, timeStamp);
                                id++;
                            }
                        }
                        //Console.ReadLine();
                        timerCount++;
                    }

                }   
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message.ToString());
                }
            }

        }
        else
        {
            myTimer.Stop();
            timerCount = 1;
        }
    }

}

}

4

0 回答 0