.net 获取CPU频率 内存 磁盘大小,域名 端口 虚拟目录等

CPU个数: @Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")

CPU类型: @Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")

CPU频率: @ViewBag.CPUGHZ

服务器内存大小: @ViewBag.TotalMemory

服务器磁盘大小: @ViewBag.TotalDisk

虚拟目录绝对路径: @Request.ServerVariables["APPL_PHYSICAL_PATH"]

执行文件绝对路径: @Request.ServerVariables["PATH_TRANSLATED"]

虚拟目录Session总数: @Session.Contents.Count

  /// <summary>
        /// 获取CPU频率
        /// </summary>
        /// <returns></returns>
        public string GetCpuGHZ()
        {
            ManagementClass mc = new ManagementClass("Win32_Processor");
            ManagementObjectCollection cpus = mc.GetInstances();

            string str = "";
            string[] mHz = new string[cpus.Count];
            int c = 0;
            ManagementObjectSearcher mySearch = new ManagementObjectSearcher("select * from Win32_Processor");
            foreach (ManagementObject mo in mySearch.Get())
            {
                double temp = Convert.ToInt64(mo.Properties["CurrentClockSpeed"].Value);
                mHz[c] = temp.ToString();
                str += (temp/1000).ToString("0.00") + "GHz,";
                c++;        
            }
            mc.Dispose();
            mySearch.Dispose();
            // return mHz;
            return str.TrimEnd(',');
        }


        /// <summary>
        /// 获取内存大小
        /// </summary>
        /// <returns></returns>
        public string GetTotalPhysicalMemory()
        {
            try
            {
                string st = " ";
                ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    st = mo["TotalPhysicalMemory"].ToString();
                }
                moc = null;
                mc = null;
                return st;
            }
            catch
            {
                return "0";
            }
            finally
            {
            }
        }

        /// <summary>
        /// 硬盘大小
        /// </summary>
        /// <returns></returns>
        public string GetSizeOfDisk()
        {
            ManagementClass mc = new ManagementClass("Win32_DiskDrive");
            ManagementObjectCollection moj = mc.GetInstances();
            foreach (ManagementObject m in moj)
            {
                return m.Properties["Size"].Value.ToString();
            }
            return "0";
        }

 

比较全的获取服务器信息:

https://www.cnblogs.com/tylerdonet/archive/2013/04/07/3006278.html

比较全的Request 用法:

https://www.cnblogs.com/mazhenyu/p/9468441.html

 

转载于:https://www.cnblogs.com/fuqiang88/p/11593767.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值