C# - 如何访问 WLAN 信号强度和其他?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1686715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 19:59:43  来源:igfitidea点击:

C# - How do I access the WLAN signal strength and others?

c#windowslocationtrackingwlan

提问by TheFlash

Many scientists have published papersdocumenting how devices connected via WLAN can be tracked by measuring its Signal Strength, Time Of Arrival, Round Trip Time, etc. Any idea how I can access these values in Windows using any .NET API?

许多科学家发表了论文,记录了如何通过测量信号强度、到达时间、往返时间等来跟踪通过 WLAN 连接的设备。知道如何使用任何 .NET API 在 Windows 中访问这些值吗?

Or do you know of software SDKs already available for location tracking?

或者您是否知道已经可用于位置跟踪的软件 SDK?

采纳答案by khadija

hello for WIndows 7 this is a good code wich can detect all AP with MAC adress RSSI SSID :

你好,对于 WINdows 7,这是一个很好的代码,它可以检测所有具有 MAC 地址 RSSI SSID 的 AP:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using NativeWifi;

class Program
{

    static void Main(string[] args)
    {

        WlanClient client = new WlanClient();
        // Wlan = new WlanClient();
        try
        {
            foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
            {

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

                foreach (Wlan.WlanBssEntry network in wlanBssEntries)
                {
                    int rss = network.rssi;
                    //     MessageBox.Show(rss.ToString());
                    byte[] macAddr = network.dot11Bssid;

                    string tMac = "";

                    for (int i = 0; i < macAddr.Length; i++)
                    {

                        tMac += macAddr[i].ToString("x2").PadLeft(2, '0').ToUpper();

                    }



                    Console.WriteLine("Found network with SSID {0}.", System.Text.ASCIIEncoding.ASCII.GetString(network.dot11Ssid.SSID).ToString());

                    Console.WriteLine("Signal: {0}%.", network.linkQuality);

                    Console.WriteLine("BSS Type: {0}.", network.dot11BssType);

                    Console.WriteLine("MAC: {0}.", tMac);

                    Console.WriteLine("RSSID:{0}", rss.ToString());


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

        }
    }  
}

i hope it will be helpful enjoy

我希望它会有所帮助享受

回答by GraemeF

Windows itself provides a Location APInow.

Windows 本身现在提供了一个位置 API

回答by Taylor Leese

The Managed Wifi APIwill provide signal strength information. Here's a code snippet adapted from a question I previously posed and was answered here:

托管无线上网API将提供信号强度信息。这是改编自我之前提出并在此处回答的问题的代码片段:

static void Main(string[] args)
{
    WlanClient client = new WlanClient();
    foreach ( WlanClient.WlanInterface wlanIface in client.Interfaces )
    {
        Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList( 0 );
        foreach ( Wlan.WlanAvailableNetwork network in networks )
        {
            Console.WriteLine( "Found network with SSID {0} and Siqnal Quality {1}.", GetStringForSSID(network.dot11Ssid), network.wlanSignalQuality);
        }
    }
}

static string GetStringForSSID(Wlan.Dot11Ssid ssid)
{
    return Encoding.ASCII.GetString(ssid.SSID, 0, (int) ssid.SSIDLength);
}