Macアドレスの読み出し(base 64の変換を含む)

2409 ワード

 string mac =null;
        /// 
        ///   MAC  
        /// 
        /// mac  
        public  ReadMac()//    MAC  
        {
            
            ManagementClass mc;
            mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject mo in moc)
            {
                if (mo["IPEnabled"].ToString() == "True")
                    mac = mo["MacAddress"].ToString();
            }            
        }
        /// 
        /// mac     base64  
        /// 
        ///   mac  
        ///     mac  
        public  string ChangeMac()
        {
            if (mac != null)
            {
                string str = mac.Replace(":", "");//  mac  ":"
                var strMac = Encoding.Default.GetBytes(str);//         
                string endStr = Convert.ToBase64String(strMac);//          base64
                //string endStr = Encoding.Default.GetString(strMac);
                return endStr;
            }
            else
            {
                return "Mac      ";
            }
        }
        /// 
        /// Mac base64    
        /// 
        /// base64    
        ///     “:” Mac
        public  string firstMac()
        {
            //var baseStr = Convert.FromBase64String (str);
            //string firstStr = Encoding.Default.GetString(baseStr);
            if (mac != null)
            {
                string firstStr = mac.Replace(":", "");
                return firstStr;
            }
            else
            {
                return "  Mac    ";
            }
        }
        /// 
        ///   Mac      
        /// 
        ///      
        /// 
        public int CheckMac(string url)
        {
            string strCheckMac= PostUpload.PostMoth(url,"mac="+ ChangeMac() , Encoding.Default);//true    ,false    
            if (strCheckMac == "true")
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }
    }