C#获取正在使用的网卡信息

/// 
        /// 获得当前机器的活动中Mac地址,若无联网则返回空""
        /// 
        /// mac地址,例如:18:03:73:AE:38:0D
        public static string GetActivatedAdaptorMacAddress()
        {
            string mac = "";
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if (mo["IPEnabled"].ToString() == "True")
                {
                    mac = mo["MacAddress"].ToString();
                }
            }
            return mac;
        }

你可能感兴趣的:(C#获取正在使用的网卡信息)