2009-01-30 5 views
25

Gibt es eine Möglichkeit, mit .NET auf alle WLAN-Zugangspunkte und ihre jeweiligen RSSI-Werte zuzugreifen? Es wäre wirklich schön, wenn ich es tun könnte, ohne unmanaged Code oder noch besser, wenn es sowohl in Mono als auch in .NET funktionierte.Wie bekomme ich die verfügbaren WLAN-APs und ihre Signalstärke in .net?

Wenn es möglich ist, würde ich ein Codebeispiel schätzen. Dank


Hier sind ein paar similiar Stackoverflow Fragen, die ich gefunden:

-Get SSID of the wireless network I am connected to with C# .Net on Windows Vista

-Managing wireless network connection in C#

- Get BSSID (MAC address) of wireless access point from C#

Antwort

17

Es ist ein Wrapper-Projekt mit verwaltetem Code in C# bei http://www.codeplex.com/managedwifi

Es unterstützt Windows Vista und XP SP2 (oder neuere Version).

Beispielcode:

using NativeWifi; 
using System; 
using System.Text; 

namespace WifiExample 
{ 
    class Program 
    { 
     /// <summary> 
     /// Converts a 802.11 SSID to a string. 
     /// </summary> 
     static string GetStringForSSID(Wlan.Dot11Ssid ssid) 
     { 
      return Encoding.ASCII.GetString(ssid.SSID, 0, (int) ssid.SSIDLength); 
     } 

     static void Main(string[] args) 
     { 
      WlanClient client = new WlanClient(); 
      foreach (WlanClient.WlanInterface wlanIface in client.Interfaces) 
      { 
       // Lists all networks with WEP security 
       Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0); 
       foreach (Wlan.WlanAvailableNetwork network in networks) 
       { 
        if (network.dot11DefaultCipherAlgorithm == Wlan.Dot11CipherAlgorithm.WEP) 
        { 
         Console.WriteLine("Found WEP network with SSID {0}.", GetStringForSSID(network.dot11Ssid)); 
        } 
       } 

       // Retrieves XML configurations of existing profiles. 
       // This can assist you in constructing your own XML configuration 
       // (that is, it will give you an example to follow). 
       foreach (Wlan.WlanProfileInfo profileInfo in wlanIface.GetProfiles()) 
       { 
        string name = profileInfo.profileName; // this is typically the network's SSID 

        string xml = wlanIface.GetProfileXml(profileInfo.profileName); 
       } 

       // Connects to a known network with WEP security 
       string profileName = "Cheesecake"; // this is also the SSID 
       string mac = "52544131303235572D454137443638"; 
       string key = "hello"; 
       string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, mac, key); 

       wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true); 
       wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName); 
      } 
     } 
    } 
} 
+0

Danke dafür. Aber es funktioniert nicht für mich. Ich benutze Windows 8.1 und bekomme diese Ausnahme "In ManagedWifi ist eine unbehandelte Ausnahme vom Typ 'System.ComponentModel.Win32Exception' aufgetreten. dll ". Irgendeine Idee? –

+0

Ich bekomme auch diesen Fehler in einer meiner Maschinen, obwohl ich es auf Windows 10 und VS 2015 laufen lasse. Irgendwelche Hinweise? Waren Sie in der Lage, es auszusortieren? – Apoorv

0

Sie könnte der Lage sein, es zu erreichen WMI-Abfragen verwenden. Werfen Sie einen Blick auf diese thread.

0

Wenn Sie vista verwenden, funktioniert wmi nicht mit allen Netzwerkadaptern, eine weitere Alternative für vista ist die Verwendung des Befehls netsh. Werfen Sie einen Blick auf this codeproject article.

+1

thx für die Verbindung. Das Problem mit Netsh ist, dass es mir nicht alle Informationen gibt, die ich brauche (rssi) und ist eine Art Buggy manchmal – LDomagala

-2

fand ich eine andere Art und Weise, es zu tun, obwohl es etwas Geld kostet.

Es gibt eine .NET-Lib verfügbar unter rawether.net, die Sie an den Ethernet-Treibern erhalten können.

Verwandte Themen