8

I'm aware of this post Get SSID of the wireless network I am connected to with C# .Net on Windows Vista It described how to get an ssid in C#. However, that library isn't supported in dotnet core. Is there a way to get the ssid and signal strength of the currently connected wifi adapter in dotnet core? I've tried playing with the NetworkInterface namespace (System.Net.NetworkInformation), and that seems to give me at least some diagnostic information about the network, but it definitely doesn't include the ssid. What do you guys think? Is this supported (yet) ?

The code I was playing with is below. It doesn't give me what I need though. I was mostly using it to explore with the debugger.

var interfaces = NetworkInterface.GetAllNetworkInterfaces();
var connected = interfaces
     .Where(i => i.OperationalStatus == OperationalStatus.Up)
     .Where(i => i.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
     .ToList();

var wifi = connected[0];
var props = wifi.GetIPProperties();
var addr = wifi.GetPhysicalAddress();
var stats = wifi.GetIPStatistics();

Thanks guys.

Community
  • 1
  • 1
cdhanna
  • 101
  • 1
  • 4

1 Answers1

2

I don't know what .NET Core version you are using, but the following NuGet package from MSFT integrates with my .NET Core 3.0 app:

Microsoft.WindowsAPICodePack-Core version 1.1.0.2

Although the library is rather old - it dates back to 2014 - and it is not conforming to .NET Standard. Obviously this is not cross-platform and works only on Windows. It does not provide the information you require, but maybe it is a useful hint to the real solution?

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

Signal strength

With the following PowerShell gist utilizing netsh you will get the signal strength:

(netsh wlan show interfaces) -Match '^\s+Signal' -Replace '^\s+Signal\s+:\s+',''

After further Googling I stubbled upon the Codeplex archive of the ManagedWlan project:

https://archive.codeplex.com/?p=managedwifi

It provides a broad range of interops with the Windows kernel APIs. I believe it also allows you to retrieve the signal strength. I have migrated the provided MIT licensed source code to a GitHub repository: https://github.com/cveld/ManagedWifi

It compiles towards .NET Core 3.0 but is obviously not cross-platform.

Carl in 't Veld
  • 1,363
  • 2
  • 14
  • 29
  • If you've answered the question in another post, it's better to mark the question as duplicate instead of copy pasting code everywhere. – itsMasoud Nov 13 '19 at 20:38
  • Good suggestion; I have been processing three questions around getting the SSID of the WLAN connection. But how do we address this question as the OP is also asking for getting the signal strength? – Carl in 't Veld Nov 13 '19 at 20:47
  • It's not that hard; Just share the duplicate link and tell him you can access signal strength with the help of powershell. S/He is able to find it in google ("Just like you"). – itsMasoud Nov 13 '19 at 21:08