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

 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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值