当前位置: 首页  >  C#  >  C#获取局域网MAC地址

C#获取局域网MAC地址 TOP

效果:

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

代码:

 
/// <summary> 
        /// 获取网卡物理地址 
        /// </summary> 
        /// <returns></returns> 
        public static string getMAC()
        {
            string madAddr = null;
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc2 = mc.GetInstances();
            foreach (ManagementObject mo in moc2)
            { www.jbxue.com
                if (Convert.ToBoolean(mo["IPEnabled"]) == true)
                {
                    madAddr = mo["MacAddress"].ToString();
                    madAddr = madAddr.Replace('':'', ''-'');
                }
                mo.Dispose();
            }
            return madAddr;
        }
Views:896   Posted at:2013-11-29
收藏 推荐 打印 | 录入:Admin | 阅读:0