欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP.NET获取客户端MAC地址

程序员文章站 2023-12-25 18:26:45
 ///         /// get MacAddress...
 /// <summary>
        /// get MacAddress
        /// </summary>
        /// <returns></returns>
        public static string GetMac()
        {www.2cto.com
            string MacAddress = String.Empty;
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"] == true)
                {
                    MacAddress = mo["MacAddress"].ToString();
                    break;
                }
            }
            moc = null;
            mc = null;
// 将MAC地址用-分割
            MacAddress = MacAddress.Replace(":", "-");
            return MacAddress;
        }

上一篇:

下一篇: