本文介绍了如何使用WMI或System.Net.NetworkInformation Windows 10在C#中获取当前已连接的WiFi SSID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了2种不同的方式
try{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSNdis_80211_ServiceSetIdentifier");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("MSNdis_80211_ServiceSetIdentifier instance");
Console.WriteLine("-----------------------------------");
if (queryObj["Ndis80211SsId"] == null)
{
//Console.WriteLine("Ndis80211SsId: {0}",queryObj["Ndis80211SsId"]);
}
else
{
Byte[] arrNdis80211SsId = (Byte[])
(queryObj["Ndis80211SsId"]);
foreach (Byte arrValue in arrNdis80211SsId)
{
//Console.WriteLine("Ndis80211SsId: {0}", arrValue);
}
}
}
}catch(Exception ex){
}
第二种方式:我正在对wi-fi进行门控,但无法获取SSID
if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) {
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) {
if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 && ni.OperationalStatus== OperationalStatus.Up ) {
Network = "NETWORK ( N/A )";
Wifi = "Wifi (" + ni.Name + ")";
}
}
}
您能不能请别人给我一个清晰的主意,让我知道如何获得连接的WiFi SSID.
Could you please someone give me clear idea how to get my connected wifi SSID.
推荐答案
// Show SSID and Signal Strength
private void showConnectedId() {
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "netsh.exe";
p.StartInfo.Arguments = "wlan show interfaces";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string s = p.StandardOutput.ReadToEnd();
string s1 = s.Substring(s.IndexOf("SSID"));
s1 = s1.Substring(s1.IndexOf(":"));
s1 = s1.Substring(2, s1.IndexOf("\n")).Trim();
string s2 = s.Substring(s.IndexOf("Signal"));
s2 = s2.Substring(s2.IndexOf(":"));
s2 = s2.Substring(2, s2.IndexOf("\n")).Trim();
labelStatus.Text = "WIFI connected to " + s1 + " " + s2;
p.WaitForExit();
}
这篇关于如何使用WMI或System.Net.NetworkInformation Windows 10在C#中获取当前已连接的WiFi SSID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!