C#获取局域网MAC地址的简单实例

效果:

说明:获取本局域网的MAC地址(非本机的MAC地址)

代码:

复制代码 代码如下:

///
        /// 获取网卡物理地址
        ///

        ///
        public static string getMAC()
        {
            string madAddr = null;
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc2 = mc.GetInstances();
            foreach (ManagementObject mo in moc2)
            {
                if (Convert.ToBoolean(mo["IPEnabled"]) == true)
                {
                    madAddr = mo["MacAddress"].ToString();
                    madAddr = madAddr.Replace(':', '-');
                }
                mo.Dispose();
            }
            return madAddr;
        }

你可能感兴趣的:(C#获取局域网MAC地址的简单实例)