Exemplo n.º 1
0
        /// <summary>
        /// 获取本机Mac
        /// </summary>
        /// <returns>返回获取本机Mac</returns>
        public static string GetLocalMac()
        {
            var mac = "00-00-00-00-00-00";

            try
            {
                ManagementObjectCollection moc2 = WMIHelper.GetObjectCollection(WMIPath.Win32_NetworkAdapterConfiguration);
                foreach (ManagementObject mo in moc2)
                {
                    if (Convert.ToBoolean(mo["IPEnabled"]))
                    {
                        mac = mo["MacAddress"].ToString();
                        mo.Dispose();
                        return(mac);
                    }
                }
                return(string.Empty);
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
            return(mac);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据适配器名称获取适配器对象
        /// </summary>
        /// <param name="name">适配器名称</param>
        public static ManagementObject GetNetworkAdapterByName(string name)
        {
            ManagementObjectCollection moc = WMIHelper.GetObjectCollection(WMIPath.Win32_NetworkAdapterConfiguration);

            foreach (ManagementObject mo in moc)
            {
                if (mo["Caption"].ToString().Equals(name))
                {
                    return(mo);
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取所有网络适配器
        /// </summary>
        public static string[] GetAllNetworkAdapter()
        {
            List <string> allNetworkAdapte = new List <string>();
            ManagementObjectCollection moc = WMIHelper.GetObjectCollection(WMIPath.Win32_NetworkAdapterConfiguration);

            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"])
                {
                    allNetworkAdapte.Add(mo["Caption"].ToString());
                }
            }
            return(allNetworkAdapte.ToArray());
        }