您的位置:首页 > 编程语言 > C#

C#获取本机当前连接的无线路由的ssid

2009-02-14 16:15 411 查看
using System;
using System.Collections.Generic;
using System.Text;

using System.Management;//System.Management.dll

namespace test_get_current_connect_console
{
class Program
{
static void Main(string[] args)
{
int i = 0;
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root//WMI","SELECT * FROM MSNdis_80211_ServiceSetIdentifier where active = true");

try
{
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"]);
Console.Write("Ndis80211SsId:");
foreach (Byte arrValue in arrNdis80211SsId)
{
if (i++ > 3)
{
if (arrValue > 0)
{
Console.Write("{0}", (char)arrValue);
}
}
}
Console.WriteLine("");
break;
}
}//end fereach
Console.ReadLine();
}
catch
{
Console.WriteLine("Error");
Console.ReadLine();
}
}// end Main
}//end class Program
}

参考:http://www.metageek.net/svn/Inssider/trunk/WmiWirelessInterface.cs<br /> http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/02e193f7-3f07-4c5c-9968-ac25ea96622b/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: