C#获取本机的MAC地址


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace _17获取MAC地址
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementObjectSearcher nisc = new ManagementObjectSearcher("select * from Win32_NetworkAdapterConfiguration");
            foreach (ManagementObject nic in nisc.Get()) 
            {
                if (Convert.ToBoolean(nic["ipEnabled"]) == true) 
                {
                    Console.WriteLine("{0} - {1}", nic["ServiceName"], nic["MACAddress"]);
                }
            }

            Console.ReadKey();
        }
    }
}



 

posted @ 2013-07-02 21:34  liqipeng  阅读(621)  评论(0编辑  收藏  举报