2009-11-06 41 views

回答

11

你好对于Windows 7,这是一个很好的代码至极可以检测到所有的AP与MAC地址RSSI SSID:

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

     } 
    } 
} 

我希望这将是有益的享受

+2

嗨科迪,你能否扩展这个例子来连接一个可用的wifi ssids? – 2011-07-07 20:51:22

+3

这个答案应该提到nativewifi命名空间可以在这里找到http://managedwifi.codeplex.com/ – Joe 2015-04-20 16:30:16

+0

是否有可能找到像802.11n,802.11g的Wifi模式? – 2017-11-21 06:41:22

1

Windows本身现在提供Location API

+0

好主意,但没有提及无线局域网跟踪,他们假设我们有GPS设备...慢和不准确。 – 2009-11-06 10:41:13

+0

位置API由“默认”技术无关,意味着它可以从任何类型的位置源获得输入。如果你想使用WLAN,只需要为Windows编写一个源驱动程序。 这将允许所有具有Location API能力的应用程序使用您的源代码,同样,您的应用程序可以使用多个源代码。但是,您会发现,对于室内定位而言,WLAN并非最佳可用解决方案。 – andy 2009-11-23 08:42:42

9

Managed Wifi API将提供信号强度信息。下面是摘自我先前提出并回答了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); 
} 
+2

+1这是一个很好的答案。非常清楚! – 2010-03-02 03:11:46