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();
}
}
}
本文介绍了一种使用C#编程语言来获取计算机中所有启用的网络适配器及其对应的MAC地址的方法。通过调用WMI (Windows Management Instrumentation) API, 该程序能够列出服务名称和服务的MAC地址。
573

被折叠的 条评论
为什么被折叠?



