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

后端 未结 7 763
难免孤独
难免孤独 2020-11-27 04:31

I\'d like to know if there is any .Net class that allows me to know the SSID of the wireless network I\'m connected to. So far I only found the library linked below. Is the

相关标签:
7条回答
  • 2020-11-27 05:19

    there is some more information in How do I get the available wifi APs and their signal strength in .net?

    0 讨论(0)
  • 2020-11-27 05:19

    I wanted to do exactly this, and tried using ManagedWifi, as suggested in other answers. But that led to unresolvable Exceptions as per here: Issues with using Managed WiFi (NativeWiFi API)

    I solved this by switching to using SimpleWiFi entirely and ignored the ManagedWifi package.

    Glancing at the source code, it looks like SW is a fixed reimplementation of some of the functionality in MW.

    0 讨论(0)
  • 2020-11-27 05:26

    We were using the managed wifi library, but it throws exceptions if the network is disconnected during a query.

    Try:

    var process = new Process
    {
        StartInfo =
        {
        FileName = "netsh.exe",
        Arguments = "wlan show interfaces",
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true
        }
    };
    process.Start();
    
    var output = process.StandardOutput.ReadToEnd();
    var line = output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(l => l.Contains("SSID") && !l.Contains("BSSID"));
    if (line == null)
    {
        return string.Empty;
    }
    var ssid = line.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries)[1].TrimStart();
    return ssid;
    
    0 讨论(0)
  • 2020-11-27 05:29

    I resolved using the library. It resulted to be quite easy to work with the classes provided:

    First I had to create a WlanClient object

    wlan = new WlanClient();
    

    And then I can get the list of the SSIDs the PC is connected to with this code:

    Collection<String> connectedSsids = new Collection<string>();
    
    foreach (WlanClient.WlanInterface wlanInterface in wlan.Interfaces)
    {
       Wlan.Dot11Ssid ssid = wlanInterface.CurrentConnection.wlanAssociationAttributes.dot11Ssid;
       connectedSsids.Add(new String(Encoding.ASCII.GetChars(ssid.SSID,0, (int)ssid.SSIDLength)));
    }
    
    0 讨论(0)
  • 2020-11-27 05:29

    (cross-posted in How to get currently connected wifi SSID in c# using WMI or System.Net.NetworkInformation windows 10?)

    I found a rather old library dating back to 2014:

    Microsoft.WindowsAPICodePack-Core version 1.1.0.2
    

    Although it is not conforming to .NET Standard, this library integrates with my .NET Core 3.0 app, but obviously is not cross-platform.

    Sample code:

    var networks = NetworkListManager.GetNetworks(NetworkConnectivityLevels.Connected);            
    foreach (var network in networks) { 
        sConnected = ((network.IsConnected == true) ? " (connected)" : " (disconnected)");
        Console.WriteLine("Network : " + network.Name + " - Category : " + network.Category.ToString() + sConnected);
    }
    
    0 讨论(0)
  • 2020-11-27 05:32

    You are going to have to use native WLAN API. There is a long discussion about it here. Apparently this is what Managed Wifi API uses, so it will be easier for you to use it if you do not have any restrictions to use LGPL code.

    0 讨论(0)
提交回复
热议问题