zoukankan      html  css  js  c++  java
  • 得到MAC地址

     /// <summary>
        /// 得到MAC地址
        /// </summary>
        /// <returns></returns>
        public string GetMacAddress()
        {
            ManagementClass mc;
            ManagementObjectCollection moc;
            try
            {
                mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                moc = mc.GetInstances();
            }
            catch
            {
                return "";
            }
            //****先得到网卡数目                      
            int i = 0;
            foreach (ManagementObject mo in moc)
            {
                if ((bool)mo["IPEnabled"] == true)
                {
                    i++;
                }
                mo.Dispose();
            }
            //***赋值给数组    
            ManagementClass mc_2 = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc_2 = mc_2.GetInstances();
            string[] array = new string[i];
            int j = 0;
            foreach (ManagementObject mo in moc_2)
            {
                if ((bool)mo["IPEnabled"] == true)
                {
                    string temp = mo["MacAddress"].ToString();
                    temp = temp.Replace(":", "-");
                    array[j] = temp;
                    j++;
                }
                mo.Dispose();

            }
            string retv = "";
            foreach (string s in array)
                retv += s;
            if (retv.Length > 17)
            {
                retv = retv.Substring(0, 17);
            }
            return retv;
        } 

  • 相关阅读:
    Docker 批量删除容器和镜像
    Matlab中xcorr命令解释
    关于递归总结
    关于STL的map的注意事项
    sublime text 3快捷键
    visual Assist常用快捷键
    学校到职场新人的总结
    Navicat for Mysql导入mysql数据库脚本文件
    欧美姓氏的来源
    linux tar.gz zip 解压缩 压缩命令
  • 原文地址:https://www.cnblogs.com/flyrain/p/MAC.html
Copyright © 2011-2022 走看看