码迷,mamicode.com
首页 > 其他好文 > 详细

c#获取电脑内部信息

时间:2014-07-14 11:09:29      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:c#获取电脑内部信息   得到电脑cpu序列号   得到客户端ip地址   c#   

        /// <summary>
        /// 得到电脑CPU序列号
        /// </summary>
        public string GetComputerCPUSerialNo()
        {
            string cpuSerialNo = string.Empty;
            System.Management.ManagementClass managementClass = new System.Management.ManagementClass("Win32_Processor");
            System.Management.ManagementObjectCollection managementObjectCollection = managementClass.GetInstances();
            foreach (System.Management.ManagementObject managementObject in managementObjectCollection)
            {
                cpuSerialNo = managementObject.Properties["ProcessorId"].Value.ToString();
                break;
            }
            return cpuSerialNo;
        }

 

    

        /// <summary>
        /// 得到客户端IP地址
        /// </summary>
        public string GetClientIdAddress()
        {
            string ip = string.Empty;
            try
            {
                if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"] == null)
                    ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
                else
                    ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"].ToString();

                if (string.IsNullOrEmpty(ip)) {
                    ip = System.Web.HttpContext.Current.Request.UserHostAddress;
                }
            }
            catch { ip = "1.1.1.1"; }
            return ip;
        }

 

c#获取电脑内部信息,布布扣,bubuko.com

c#获取电脑内部信息

标签:c#获取电脑内部信息   得到电脑cpu序列号   得到客户端ip地址   c#   

原文地址:http://blog.csdn.net/y_f123/article/details/37742049

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!