现在的位置: 首页 > 综合 > 正文

自己写了一个Asp.net探针的源码,希望大家讨论一下

2012年02月13日 ⁄ 综合 ⁄ 共 3491字 ⁄ 字号 评论关闭

现在针对Asp.net的探针很少,所以闲来无事就简单的写了一个,读取的信息如下

服务器基本信息
服务器计算机名 http://localhost/
服务器IP地址 127.0.0.1
服务器域名 localhost
服务器端口 80
服务器IIS版本 Microsoft-IIS/6.0
本文件所在文件夹 E:\downCode\ServerInfo\
服务器操作系统 Microsoft Windows NT 5.2.3790 Service Pack 1
系统所在文件夹 C:\WINDOWS\system32
服务器脚本超时时间 30000秒
服务器的语言种类 Chinese (People's Republic of China)
.NET Framework 版本 2.050727.42
服务器当前时间 2007-5-25 9:32:55
服务器IE版本 7.0000
服务器上次启动到现在已运行 66分钟
逻辑驱动器 A:\C:\D:\E:\F:\G:\H:\I:\
CPU 总数 2
CPU 类型 x86 Family 15 Model 3 Stepping 4, GenuineIntel
虚拟内存 61784M
当前程序占用内存 6.44M
Asp.net所占内存 60.46M
Asp.net所占CPU 4
当前Session数量 0
当前SessionID gp3n1u55f2qcse55xo3q2x45
当前系统用户名 NETWORK SERVICE

由于还不是很成熟,所以暂时开源供大家讨论,希望能得到高手的补充!暂定版本0.90

以下是源码部分

 1
 2    /// <summary>
 3    /// Asp.net服务器探针,Power by 51aspx.com
 4    /// 作者liudao,51aspx.com版权所有 转载请保留版权信息
 5    /// </summary>

 6    public partial class _Default : System.Web.UI.Page
 7    {
 8        protected void Page_Load(object sender, EventArgs e)
 9        {
10            if (!IsPostBack)
11            {
12         /// <summary>
13          /// 取应用程序路径
14         /// </summary>

15
16        lbServerName.Text= "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath;
17        lbIp.Text = Request.ServerVariables["LOCAl_ADDR"];
18        lbDomain.Text = Request.ServerVariables["SERVER_NAME"].ToString();
19        lbPort.Text = Request.ServerVariables["Server_Port"].ToString();
20        lbIISVer.Text = Request.ServerVariables["Server_SoftWare"].ToString();
21        lbPhPath.Text = Request.PhysicalApplicationPath;
22        lbOperat.Text = Environment.OSVersion.ToString();
23        lbSystemPath.Text = Environment.SystemDirectory.ToString();
24        lbTimeOut.Text = (Server.ScriptTimeout/1000).ToString() + "";
25        lbLan.Text =  CultureInfo.InstalledUICulture.EnglishName;
26        lbAspnetVer.Text = string.Concat(new object[] { Environment.Version.Major, ".", Environment.Version.Minor, Environment.Version.Build, ".", Environment.Version.Revision });
27        lbCurrentTime.Text = DateTime.Now.ToString();
28               
29                RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Version Vector");
30        lbIEVer.Text = key.GetValue("IE""未检测到").ToString();
31        lbServerLastStartToNow.Text = ((Environment.TickCount / 0x3e8)/60).ToString() + "分钟";
32
33        string[] achDrives = Directory.GetLogicalDrives();
34        for (int i = 0; i < Directory.GetLogicalDrives().Length - 1; i++)
35        {
36            lbLogicDriver.Text = lbLogicDriver.Text + achDrives[i].ToString();
37        }

38
39        //ManagementClass diskClass = new ManagementClass("NUMBER_OF_PROCESSORS");
40        lbCpuNum.Text = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS").ToString();
41        lbCpuType.Text = Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER").ToString();
42        lbMemory.Text = (Environment.WorkingSet / 1024).ToString()+ "M";
43        lbMemoryPro.Text = ((Double)GC.GetTotalMemory(false/ 1048576).ToString("N2"+ "M";
44        lbMemoryNet.Text = ((Double)Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2"+ "M";
45        lbCpuNet.Text = ((TimeSpan)Process.GetCurrentProcess().TotalProcessorTime).TotalSeconds.ToString("N0");
46        lbSessionNum.Text = Session.Contents.Count.ToString();
47        lbSession.Text = Session.Contents.SessionID;
48                lbUser.Text = Environment.UserName;
49
50            }

51        }

52    }

注意:当前版本只支持Asp.net2.0环境

另外根据大家的补充版本不断升级中,敬请关注!
作者liudao
51aspx.com版权所有 转载请保留版权信息

另外提供完整项目源码供大家下载,见笑了!

抱歉!评论已关闭.