I want to judge if the computer running my program is in a certain network. I have tried the code below
ManagementClass vNetworkAdapter = new ManagementClass("Win32_NetworkAdapter");
ManagementObjectCollection vNetworkAdapters = vNetworkAdapter.GetInstances();
foreach (ManagementObject vNetworkAdapterInfo in vNetworkAdapters)
{
string ID = (string)vNetworkAdapterInfo.Properties["NetConnectionID"].Value;
string Caption = (string)vNetworkAdapterInfo.Properties["Caption"].Value;
string Description = (string)vNetworkAdapterInfo.Properties["Description"].Value;
string SSID = (string)vNetworkAdapterInfo.Properties["DeviceID"].Value;
if (ID != null)
{
if (ID == "以太网")//judge certain type of connection by name, I only considered the wired and wireless connection
{
Console.WriteLine("以太网" + "\n" + Caption + "\n" + Description);
Console.WriteLine(SSID);
}
else if (ID == "WLAN")
{
Console.WriteLine("WLAN" + "\n" + Caption + "\n" + Description);
Console.WriteLine(SSID);
}
}
Console.WriteLine("");
}
It returns With
WLAN
[00000002] Killer(R) Wi-Fi 6 AX1650i 160MHz Wireless Network Adapter (201NGW)
Killer(R) Wi-Fi 6 AX1650i 160MHz Wireless Network Adapter (201NGW)
以太网
[00000003] Killer E2500 Gigabit Ethernet Controller
Killer E2500 Gigabit Ethernet Controller
But I not wanting this name, I want to get the name shown when we are connecting to a certain network(known as SSID for wireless connection), What I should do? thanks a lot!