【问题标题】:C# - How do I access the WLAN signal strength and others?C# - 如何访问 WLAN 信号强度和其他?
【发布时间】:2010-12-13 18:57:34
【问题描述】:

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

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

【问题讨论】:

标签: c# windows location tracking wifi


【解决方案1】:

你好,对于 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);
        }

        }
    }  
}

希望对你有帮助

【讨论】:

  • 嗨 Cody,您能否扩展此示例以连接到可用的 wifi ssid 之一?
  • 这个答案应该提到可以在这里找到nativewifi命名空间managedwifi.codeplex.com
  • 是否可以找到像 802.11n、802.11g 这样的 Wifi 模式?
【解决方案2】:

Managed Wifi API 将提供信号强度信息。这是一个代码 sn-p 改编自我之前提出的问题并得到了回答 here:

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);
}

【讨论】:

    【解决方案3】:

    Windows 本身现在提供Location API

    【讨论】:

    • 好主意,但没有提到 WLAN 跟踪,他们假设我们有 GPS 设备......速度慢且不准确。
    • Location API “默认”与技术无关,这意味着它可以从任何类型的位置源获得输入。如果您想使用 WLAN,只需为 Windows 编写源“驱动程序”即可。这将允许所有支持 Location API 的应用程序利用您的源,同样您的应用程序可以使用多个源。但是,您会发现对于室内定位来说,WLAN 并不是最好的解决方案。
    猜你喜欢
    • 2010-11-14
    • 2013-10-17
    • 2011-12-29
    • 2011-09-03
    • 1970-01-01
    • 2018-05-14
    • 2015-12-02
    • 2013-10-10
    • 2016-04-24
    相关资源
    最近更新 更多