ASP.Net的系統信息探針(探測器)

  1. <%@ Page Language="C#" AutoEventWireup="true" %>
  2. <%@ Import Namespace="System.Runtime.InteropServices" %>
  3. <%@ Import Namespace="System.IO" %>
  4. <%@ Import Namespace="System.Data" %>
  5. <%@ Import Namespace="System.Reflection" %>
  6. <%@ Import Namespace="System.Collections" %>
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head runat="server">
  9.     <title>System Information</title>
  10.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  11.     <style type="text/css">
  12.       a:link {color: #000099; text-decoration: none; background-color: #ffffff;}
  13.       a:hover {text-decoration: underline;}
  14.       body {font-family: Georgia, "Times New Roman", Times, serif; text-align: center}
  15.       table {margin-left: auto; margin-right: auto; text-align: left; border-collapse: collapse; border:0;}
  16.       td, th {border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
  17.       .title {font-size: 150%;}
  18.       .section {text-align: center;}
  19.       .header {text-align: center; background-color: #9999cc; font-weight: bold; color: #000000;}
  20.       .name {background-color: #ccccff; font-weight: bold; color: #000000;}
  21.       .value {background-color: #cccccc; color: #000000;}
  22.       .value_true {background-color: #cccccc; color: #00ff00;}
  23.       .value_false {background-color: #cccccc; color: #ff0000;}
  24.     </style>
  25. </head>
  26. <body>
  27.     <div id="divCenter" class="center" runat="server"></div>
  28. </body>
  29. </html>
  30. <script runat="server">
  31.     #region Assistance Class
  32.     public class SystemInfo
  33.     {
  34.         [DllImport("kernel32", CharSetCharSet = CharSet.Auto, SetLastError = true)]
  35.         internal static extern void GetSystemInfo(ref CpuInfo cpuinfo);
  36.         [DllImport("kernel32", CharSetCharSet = CharSet.Auto, SetLastError = true)]
  37.         internal static extern void GlobalMemoryStatus(ref MemoryInfo meminfo);
  38.         [StructLayout(LayoutKind.Sequential)]
  39.         public struct CpuInfo
  40.         {
  41.             public uint dwOemId;
  42.             public uint dwPageSize;
  43.             public uint lpMinimumApplicationAddress;
  44.             public uint lpMaximumApplicationAddress;
  45.             public uint dwActiveProcessorMask;
  46.             public uint dwNumberOfProcessors;
  47.             public uint dwProcessorType;
  48.             public uint dwAllocationGranularity;
  49.             public uint dwProcessorLevel;
  50.             public uint dwProcessorRevision;
  51.         }
  52.         [StructLayout(LayoutKind.Sequential)]
  53.         public struct MemoryInfo
  54.         {
  55.             public uint dwLength;
  56.             public uint dwMemoryLoad;
  57.             public uint dwTotalPhys;
  58.             public uint dwAvailPhys;
  59.             public uint dwTotalPageFile;
  60.             public uint dwAvailPageFile;
  61.             public uint dwTotalVirtual;
  62.             public uint dwAvailVirtual;
  63.         }
  64.         public static MemoryInfo Memory
  65.         {
  66.             get
  67.             {
  68.                 MemoryInfo obj = new MemoryInfo();
  69.                 GlobalMemoryStatus(ref obj);
  70.                 return obj;
  71.             }
  72.         }
  73.         public static CpuInfo Cpu
  74.         {
  75.             get
  76.             {
  77.                 CpuInfo obj = new CpuInfo();
  78.                 GetSystemInfo(ref obj);
  79.                 return obj;
  80.             }
  81.         }
  82.     }
  83.     #endregion
  84.     #region Get Information Function
  85.     private DataTable GetSystemInfo()
  86.     {
  87.         DataTable table = GenerateDataTable("System Information");
  88.         //  Server Name
  89.         Assign(table, "Server Name", Server.MachineName);
  90.         Assign(table, "Server IP", Request.ServerVariables["LOCAl_ADDR"]);
  91.         Assign(table, "Server Domain", Request.ServerVariables["Server_Name"]);
  92.         Assign(table, "Server Port", Request.ServerVariables["Server_Port"]);
  93.         //  Web Server
  94.         Assign(table, "Web Server Version", Request.ServerVariables["Server_SoftWare"]);
  95.         //  Path
  96.         Assign(table, "Virtual Request Path", Request.FilePath);
  97.         Assign(table, "Physical Request Path", Request.PhysicalPath);
  98.         Assign(table, "Virtual Application Root Path", Request.ApplicationPath);
  99.         Assign(table, "Physical Application Root Path", Request.PhysicalApplicationPath);
  100.         //  Platform
  101.         OperatingSystem os = Environment.OSVersion;
  102.         string text = string.Empty;
  103.         switch (os.Platform)
  104.         {
  105.             case PlatformID.Win32Windows:
  106.                 switch (os.Version.Minor)
  107.                 {
  108.                     case 0:
  109.                         text = "Microsoft Windows 95";
  110.                         break;
  111.                     case 10:
  112.                         text = "Microsoft Windows 98";
  113.                         break;
  114.                     case 90:
  115.                         text = "Microsoft Windows Millennium Edition";
  116.                         break;
  117.                     default:
  118.                         text = "Microsoft Windows 95 or later";
  119.                         break;
  120.                 }
  121.                 break;
  122.             case PlatformID.Win32NT:
  123.                 switch (os.Version.Major)
  124.                 {
  125.                     case 3:
  126.                         text = "Microsoft Windows NT 3.51";
  127.                         break;
  128.                     case 4:
  129.                         text = "Microsoft Windows NT 4.0";
  130.                         break;
  131.                     case 5:
  132.                         switch (os.Version.Minor)
  133.                         {
  134.                             case 0:
  135.                                 text = "Microsoft Windows 2000";
  136.                                 break;
  137.                             case 1:
  138.                                 text = "Microsoft Windows XP";
  139.                                 break;
  140.                             case 2:
  141.                                 text = "Microsoft Windows 2003";
  142.                                 break;
  143.                             default:
  144.                                 text = "Microsoft NT 5.x";
  145.                                 break;
  146.                         }
  147.                         break;
  148.                     case 6:
  149.                         text = "Microsoft Windows Vista or 2008 Server";
  150.                         break;
  151.                 }
  152.                 break;
  153.             default:
  154.                 if ((int)os.Platform > 3)
  155.                 {
  156.                     string name = "/proc/version";
  157.                     if (File.Exists(name))
  158.                     {
  159.                         using (StreamReader reader = new StreamReader(name))
  160.                         {
  161.                             text = reader.ReadToEnd().Trim();
  162.                         }
  163.                     }
  164.                 }
  165.                 break;
  166.         }
  167.         text = string.Format("{0} -- {1}", text, os.ToString());
  168.         Assign(table, "Operating System", text);
  169.         Assign(table, "Operating System Installation Directory", Environment.SystemDirectory);
  170.         Assign(table, ".Net Version", Environment.Version.ToString());
  171.         Assign(table, ".Net Language", System.Globalization.CultureInfo.InstalledUICulture.EnglishName);
  172.         Assign(table, "Server Current Time", DateTime.Now.ToString());
  173.         Assign(table, "System Uptime", TimeSpan.FromMilliseconds(Environment.TickCount).ToString());
  174.         Assign(table, "Script Timeout", TimeSpan.FromSeconds(Server.ScriptTimeout).ToString());
  175.         return table;
  176.     }
  177.     private void GetSystemStorageInfo_DriveInfo(DataTable table)
  178.     {
  179.         try
  180.         {
  181.             Type typeDriveInfo = Type.GetType("System.IO.DriveInfo");
  182.             MethodInfo get_drives = typeDriveInfo.GetMethod("GetDrives");
  183.             object result = get_drives.Invoke(null, null);
  184.             foreach (object o in (IEnumerable)result)
  185.             {
  186.                 try
  187.                 {
  188.                     //  Use reflection to call DriveInfo.GetProperties() to make 1.x compiler don't complain.
  189.                     PropertyInfo[] props = typeDriveInfo.GetProperties();
  190.                     bool is_ready = (bool)typeDriveInfo.GetProperty("IsReady").GetValue(o, null);
  191.                     string name = string.Empty;
  192.                     string volume_label = string.Empty;
  193.                     string drive_format = string.Empty;
  194.                     string drive_type = string.Empty;
  195.                     ulong total_free_space = 0;
  196.                     ulong total_space = 0;
  197.                     foreach (PropertyInfo prop in props)
  198.                     {
  199.                         switch (prop.Name)
  200.                         {
  201.                             case "Name":
  202.                                 name = (string)prop.GetValue(o, null);
  203.                                 break;
  204.                             case "VolumeLabel":
  205.                                 if (is_ready)
  206.                                     volume_label = (string)prop.GetValue(o, null);
  207.                                 break;
  208.                             case "DriveFormat":
  209.                                 if (is_ready)
  210.                                     drive_format = (string)prop.GetValue(o, null);
  211.                                 break;
  212.                             case "DriveType":
  213.                                 drive_type = prop.GetValue(o, null).ToString();
  214.                                 break;
  215.                             case "TotalFreeSpace":
  216.                                 if (is_ready)
  217.                                     total_free_space = (ulong)(long)prop.GetValue(o, null);
  218.                                 break;
  219.                             case "TotalSize":
  220.                                 if (is_ready)
  221.                                     total_space = (ulong)(long)prop.GetValue(o, null);
  222.                                 break;
  223.                         }
  224.                     }
  225.                     string label = string.Empty;
  226.                     string size = string.Empty;
  227.                     if (is_ready)
  228.                     {
  229.                         label = string.Format("{0} - <{1}> [{2}] - {3,-10}", name, volume_label, drive_format, drive_type);
  230.                         if (total_space > 0 && total_space != ulong.MaxValue && total_space != int.MaxValue)
  231.                         {
  232.                             size = string.Format("Free {0} / Total {1}", FormatNumber(total_free_space), FormatNumber(total_space));
  233.                         }
  234.                     }
  235.                     else
  236.                     {
  237.                         label = string.Format("{0} {1,-10}", name, drive_type);
  238.                     }
  239.                     Assign(table, label, size);
  240.                 }
  241.                 catch (Exception) { }
  242.             }
  243.         }
  244.         catch (Exception) { }
  245.     }
  246.     private void GetSystemStorageInfo_WMI(DataTable table)
  247.     {
  248.         try
  249.         {
  250.             //  Use reflection to call WMI to make Mono compiler don't complain about assembly reference
  251.             Assembly dSystemManangement = Assembly.Load("System.Management, Version=1.0.5000.0, Culture=neutralPublicKeyToken=B03F5F7F11D50A3A");
  252.             if (dSystemManangement == null) return;
  253.             Type tManagementObjectSearcher = dSystemManangement.GetType("System.Management.ManagementObjectSearcher");
  254.             if (dSystemManangement == null) return;
  255.             MethodInfo mGet = tManagementObjectSearcher.GetMethod("Get", new Type[] { });
  256.             ConstructorInfo ctor = tManagementObjectSearcher.GetConstructor(new Type[] { typeof(string) });
  257.             object searcher = ctor.Invoke(new object[] { "Select * From Win32_LogicalDisk" });
  258.             if (dSystemManangement == null) return;
  259.             object disks = mGet.Invoke(searcher, null);
  260.             //  ManagementObject
  261.             Type tManagementObject = dSystemManangement.GetType("System.Management.ManagementObject");
  262.             foreach (object disk in (IEnumerable)disks)
  263.             {
  264.                 try
  265.                 {
  266.                     PropertyInfo prop = tManagementObject.GetProperty("Item", new Type[] { typeof(string) });
  267.                     uint i_drive_type = (uint)prop.GetValue(disk, new object[] { "DriveType" });
  268.                     string drive_type = string.Empty;
  269.                     switch (i_drive_type)
  270.                     {
  271.                         case 1:
  272.                             drive_type = "No Root Directory";
  273.                             break;
  274.                         case 2:
  275.                             drive_type = "Removable Disk";
  276.                             break;
  277.                         case 3:
  278.                             drive_type = "Local Disk";
  279.                             break;
  280.                         case 4:
  281.                             drive_type = "Network Drive";
  282.                             break;
  283.                         case 5:
  284.                             drive_type = "Compact Disc";
  285.                             break;
  286.                         case 6:
  287.                             drive_type = "RAM Disk";
  288.                             break;
  289.                         default:
  290.                             drive_type = "Unknown";
  291.                             break;
  292.                     }
  293.                     string name = prop.GetValue(disk, new object[] { "Name" }) as string;
  294.                     string volume_label = prop.GetValue(disk, new object[] { "VolumeName" }) as string;
  295.                     string filesystem = prop.GetValue(disk, new object[] { "FileSystem" }) as string;
  296.                     string free_space = string.Empty;
  297.                     try { free_space = FormatNumber((ulong)prop.GetValue(disk, new object[] { "FreeSpace" })); }
  298.                     catch (Exception) { }
  299.                     string total_space = string.Empty;
  300.                     try { total_space = FormatNumber((ulong)prop.GetValue(disk, new object[] { "Size" })); }
  301.                     catch (Exception) { }
  302.                     string left = string.Format("{0} - <{1}> [{2}] - {3,-10}",
  303.                             name,
  304.                             volume_label,
  305.                             filesystem,
  306.                             drive_type
  307.                         );
  308.                     string right = ((free_space == null || free_space == "") ? string.Empty : string.Format("Free {0} / Total {1}", free_space, total_space));
  309.                     Assign(table, left, right);
  310.                 }
  311.                 catch (Exception exception) { Assign(table, "Exception Occurs", exception.ToString()); }
  312.             }
  313.         }
  314.         catch (Exception exception) { Assign(table, "Exception Occurs", exception.ToString()); }
  315.     }
  316.     private DataTable GetSystemStorageInfo()
  317.     {
  318.         DataTable table = GenerateDataTable("Storage Information");
  319.         try { Assign(table, "Logical Driver Information", string.Join(", ", Directory.GetLogicalDrives())); }
  320.         catch (Exception) { }
  321.         if (Environment.Version.Major >= 2)
  322.         {
  323.             GetSystemStorageInfo_DriveInfo(table);
  324.         }
  325.         else
  326.         {
  327.             if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  328.             {
  329.                 GetSystemStorageInfo_WMI(table);
  330.             }
  331.         }
  332.         return table;
  333.     }
  334.     private void GetSystemMemoryInfo_proc(DataTable table)
  335.     {
  336.         string name = "/proc/meminfo";
  337.         if (File.Exists(name))
  338.         {
  339.             using (StreamReader reader = new StreamReader(name, Encoding.ASCII))
  340.             {
  341.                 Hashtable ht = new Hashtable();
  342.                 string line = string.Empty;
  343.                 while ((line = reader.ReadLine()) != null)
  344.                 {
  345.                     string[] item = line.Split(":".ToCharArray());
  346.                     if (item.Length == 2)
  347.                     {
  348.                         string k = item[0].Trim();
  349.                         string v = item[1].Trim();
  350.                         ht.Add(k, v);
  351.                     }
  352.                 }
  353.                 Assign(table, "Physical Memory Size", string.Format("{0}", ht["MemTotal"]));
  354.                 Assign(table, "Physical Free Memory Size", string.Format("{0}", ht["MemFree"]));
  355.                 Assign(table, "Swap Total Size", string.Format("{0}", ht["SwapTotal"]));
  356.                 Assign(table, "Swap Free Size", string.Format("{0}", ht["SwapFree"]));
  357.             }
  358.         }
  359.     }
  360.     private DataTable GetSystemMemoryInfo()
  361.     {
  362.         DataTable table = GenerateDataTable("Memory Information"); ;
  363.         Assign(table, "Current Working Set", FormatNumber((ulong)Environment.WorkingSet));
  364.         try
  365.         {
  366.             if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  367.             {
  368.                 SystemInfo.MemoryInfo memory = SystemInfo.Memory;
  369.                 Assign(table, "Physical Memory Size", FormatNumber(memory.dwTotalPhys));
  370.                 Assign(table, "Physical Free Memory Size", FormatNumber(memory.dwAvailPhys));
  371.                 Assign(table, "PageFile Size", FormatNumber(memory.dwTotalPageFile));
  372.                 Assign(table, "Available PageFile Size", FormatNumber(memory.dwAvailPageFile));
  373.                 Assign(table, "Virtual Memory Size", FormatNumber(memory.dwTotalVirtual));
  374.                 Assign(table, "Available Memory Size", FormatNumber(memory.dwAvailVirtual));
  375.                 Assign(table, "Memory Load", string.Format("{0} %", memory.dwMemoryLoad.ToString("N")));
  376.             }
  377.             else if ((int)Environment.OSVersion.Platform > 3)
  378.             {
  379.                 GetSystemMemoryInfo_proc(table);
  380.             }
  381.         }
  382.         catch (Exception) { }
  383.         return table;
  384.     }
  385.     private void GetSystemProcessorInfo_WMI(DataTable table)
  386.     {
  387.         //  Use reflection to call WMI to make Mono compiler don't complain about assembly reference
  388.         Assembly dSystemManangement = Assembly.Load("System.Management, Version=1.0.5000.0, Culture=neutralPublicKeyToken=B03F5F7F11D50A3A");
  389.         if (dSystemManangement == null) return;
  390.         Type tManagementObjectSearcher = dSystemManangement.GetType("System.Management.ManagementObjectSearcher");
  391.         if (dSystemManangement == null) return;
  392.         MethodInfo mGet = tManagementObjectSearcher.GetMethod("Get", new Type[] { });
  393.         ConstructorInfo ctor = tManagementObjectSearcher.GetConstructor(new Type[] { typeof(string) });
  394.         object searcher = ctor.Invoke(new object[] { "Select * From Win32_Processor" });
  395.         if (dSystemManangement == null) return;
  396.         object processors = mGet.Invoke(searcher, null);
  397.         //  ManagementObject
  398.         Type tManagementObject = dSystemManangement.GetType("System.Management.ManagementObject");
  399.         foreach (object processor in (IEnumerable)processors)
  400.         {
  401.             try
  402.             {
  403.                 try
  404.                 {
  405.                     PropertyInfo prop = tManagementObject.GetProperty("Item", new Type[] { typeof(string) });
  406.                     StringBuilder sb = new StringBuilder();
  407.                     //  Unique ID
  408.                     string name = (string)prop.GetValue(processor, new object[] { "Name" });
  409.                     sb.Append(name);
  410.                     //  Clock Speed
  411.                     uint clock_speed = (uint)prop.GetValue(processor, new object[] { "CurrentClockSpeed" });
  412.                     //  Max Clock Speed
  413.                     uint max_clock_speed = (uint)prop.GetValue(processor, new object[] { "MaxClockSpeed" });
  414.                     sb.AppendFormat(" - {0} MHz / {1} MHz", clock_speed, max_clock_speed);
  415.                     //  Current Voltage
  416.                     ushort i_current_voltage = (ushort)prop.GetValue(processor, new object[] { "CurrentVoltage" });
  417.                     double current_voltage = 0;
  418.                     if (((uint)i_current_voltage & 0x80) == 0)
  419.                     {
  420.                         current_voltage = (double)(i_current_voltage & 0x7F) / 10.0;
  421.                     }
  422.                     else
  423.                     {
  424.                         try
  425.                         {
  426.                             uint caps = (uint)prop.GetValue(processor, new object[] { "VoltageCaps" });
  427.                             switch (caps & 0xF)
  428.                             {
  429.                                 case 1:
  430.                                     current_voltage = 5;
  431.                                     break;
  432.                                 case 2:
  433.                                     current_voltage = 3.3;
  434.                                     break;
  435.                                 case 3:
  436.                                     current_voltage = 2.9;
  437.                                     break;
  438.                             }
  439.                         }
  440.                         catch (Exception) { }
  441.                     }
  442.                     if (current_voltage > 0)
  443.                     {
  444.                         sb.AppendFormat(" - {0}v", current_voltage);
  445.                     }
  446.                     //  Load Percentage 
  447.                     ushort load_percentage = (ushort)prop.GetValue(processor, new object[] { "LoadPercentage" });
  448.                     sb.AppendFormat(" - Load = {0} %", load_percentage);
  449.                     Assign(table, "Processor", sb.ToString());
  450.                 }
  451.                 catch (Exception exception) { Assign(table, "Exception Occurs", exception.ToString()); }
  452.             }
  453.             catch (Exception) { }
  454.         }
  455.     }
  456.     private void GetSystemProcessorInfo_proc(DataTable table)
  457.     {
  458.         string name = "/proc/cpuinfo";
  459.         if (File.Exists(name))
  460.         {
  461.             using (StreamReader reader = new StreamReader(name, Encoding.ASCII))
  462.             {
  463.                 ArrayList processors = new ArrayList();
  464.                 Hashtable ht = new Hashtable();
  465.                 string line = string.Empty;
  466.                 while ((line = reader.ReadLine()) != null)
  467.                 {
  468.                     if (line.Trim().Length == 0)
  469.                     {
  470.                         processors.Add(ht);
  471.                         ht = new Hashtable();
  472.                     }
  473.                     string[] item = line.Split(":".ToCharArray());
  474.                     if (item.Length == 2)
  475.                     {
  476.                         string k = item[0].Trim();
  477.                         string v = item[1].Trim();
  478.                         ht.Add(k, v);
  479.                     }
  480.                 }
  481.                 foreach (Hashtable processor in processors)
  482.                 {
  483.                     string n = string.Format("Processor {0}", processor["processor"]);
  484.                     string v = string.Format("{0}{1}", processor["model name"],
  485.                                              (processor["cpu MHz"] != null) ? string.Format(" - {0} MHz", processor["cpu MHz"]) : string.Empty);
  486.                     Assign(table, n, v);
  487.                 }
  488.             }
  489.         }
  490.     }
  491.     private DataTable GetSystemProcessorInfo()
  492.     {
  493.         DataTable table = GenerateDataTable("Processor Information");
  494.         try
  495.         {
  496.             if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  497.             {
  498.                 Assign(table, "Number of Processors", Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"));
  499.                 Assign(table, "Processor Id", Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER"));
  500.                 SystemInfo.CpuInfo cpu = SystemInfo.Cpu;
  501.                 Assign(table, "Processor Type", cpu.dwProcessorType.ToString());
  502.                 Assign(table, "Processor Level", cpu.dwProcessorLevel.ToString());
  503.                 Assign(table, "Processor OEM Id", cpu.dwOemId.ToString());
  504.                 Assign(table, "Page Size", cpu.dwPageSize.ToString());
  505.                 GetSystemProcessorInfo_WMI(table);
  506.             }
  507.             else if ((int)Environment.OSVersion.Platform > 3)
  508.             {
  509.                 GetSystemProcessorInfo_proc(table);
  510.             }
  511.         }
  512.         catch (Exception) { }
  513.         return table;
  514.     }
  515.     private DataTable GetServerVariables()
  516.     {
  517.         DataTable table = GenerateDataTable("Server Variables");
  518.         foreach (string key in Request.ServerVariables.AllKeys)
  519.         {
  520.             Assign(table, key, Request.ServerVariables[key]);
  521.         }
  522.         return table;
  523.     }
  524.     private DataTable GetEnvironmentVariables()
  525.     {
  526.         DataTable table = GenerateDataTable("Environment Variables");
  527.         foreach (DictionaryEntry de in System.Environment.GetEnvironmentVariables())
  528.         {
  529.             Assign(table, de.Key.ToString(), de.Value.ToString());
  530.         }
  531.         return table;
  532.     }
  533.     private DataTable GetSystemObjectInfo()
  534.     {
  535.         DataTable table = GenerateDataTable("System COM Component Information");
  536.         Assign(table, "Adodb.Connection", TestObject("Adodb.Connection").ToString());
  537.         Assign(table, "Adodb.RecordSet", TestObject("Adodb.RecordSet").ToString());
  538.         Assign(table, "Adodb.Stream", TestObject("Adodb.Stream").ToString());
  539.         Assign(table, "Scripting.FileSystemObject", TestObject("Scripting.FileSystemObject").ToString());
  540.         Assign(table, "Microsoft.XMLHTTP", TestObject("Microsoft.XMLHTTP").ToString());
  541.         Assign(table, "WScript.Shell", TestObject("WScript.Shell").ToString());
  542.         Assign(table, "MSWC.AdRotator", TestObject("MSWC.AdRotator").ToString());
  543.         Assign(table, "MSWC.BrowserType", TestObject("MSWC.BrowserType").ToString());
  544.         Assign(table, "MSWC.NextLink", TestObject("MSWC.NextLink").ToString());
  545.         Assign(table, "MSWC.Tools", TestObject("MSWC.Tools").ToString());
  546.         Assign(table, "MSWC.Status", TestObject("MSWC.Status").ToString());
  547.         Assign(table, "MSWC.Counters", TestObject("MSWC.Counters").ToString());
  548.         Assign(table, "IISSample.ContentRotator", TestObject("IISSample.ContentRotator").ToString());
  549.         Assign(table, "IISSample.PageCounter", TestObject("IISSample.PageCounter").ToString());
  550.         Assign(table, "MSWC.PermissionChecker", TestObject("MSWC.PermissionChecker").ToString());
  551.         return table;
  552.     }
  553.     private DataTable GetMailObjectInfo()
  554.     {
  555.         DataTable table = GenerateDataTable("Mail COM Component Information");
  556.         Assign(table, "JMail.SMTPMail", TestObject("JMail.SMTPMail").ToString());
  557.         Assign(table, "JMail.Message", TestObject("JMail.Message").ToString());
  558.         Assign(table, "CDONTS.NewMail", TestObject("CDONTS.NewMail").ToString());
  559.         Assign(table, "CDO.Message", TestObject("CDO.Message").ToString());
  560.         Assign(table, "Persits.MailSender", TestObject("Persits.MailSender").ToString());
  561.         Assign(table, "SMTPsvg.Mailer", TestObject("SMTPsvg.Mailer").ToString());
  562.         Assign(table, "DkQmail.Qmail", TestObject("DkQmail.Qmail").ToString());
  563.         Assign(table, "SmtpMail.SmtpMail.1", TestObject("SmtpMail.SmtpMail.1").ToString());
  564.         Assign(table, "Geocel.Mailer.1", TestObject("Geocel.Mailer.1").ToString());
  565.         return table;
  566.     }
  567.     private DataTable GetUploadObjectInfo()
  568.     {
  569.         DataTable table = GenerateDataTable("Upload COM Component Information");
  570.         Assign(table, "LyfUpload.UploadFile", TestObject("LyfUpload.UploadFile").ToString());
  571.         Assign(table, "Persits.Upload", TestObject("Persits.Upload").ToString());
  572.         Assign(table, "Ironsoft.UpLoad", TestObject("Ironsoft.UpLoad").ToString());
  573.         Assign(table, "aspcn.Upload", TestObject("aspcn.Upload").ToString());
  574.         Assign(table, "SoftArtisans.FileUp", TestObject("SoftArtisans.FileUp").ToString());
  575.         Assign(table, "SoftArtisans.FileManager", TestObject("SoftArtisans.FileManager").ToString());
  576.         Assign(table, "Dundas.Upload", TestObject("Dundas.Upload").ToString());
  577.         Assign(table, "w3.upload", TestObject("w3.upload").ToString());
  578.         return table;
  579.     }
  580.     private DataTable GetGraphicsObjectInfo()
  581.     {
  582.         DataTable table = GenerateDataTable("Graphics COM Component Information");
  583.         Assign(table, "SoftArtisans.ImageGen", TestObject("SoftArtisans.ImageGen").ToString());
  584.         Assign(table, "W3Image.Image", TestObject("W3Image.Image").ToString());
  585.         Assign(table, "Persits.Jpeg", TestObject("Persits.Jpeg").ToString());
  586.         Assign(table, "XY.Graphics", TestObject("XY.Graphics").ToString());
  587.         Assign(table, "Ironsoft.DrawPic", TestObject("Ironsoft.DrawPic").ToString());
  588.         Assign(table, "Ironsoft.FlashCapture", TestObject("Ironsoft.FlashCapture").ToString());
  589.         return table;
  590.     }
  591.     private DataTable GetOtherObjectInfo()
  592.     {
  593.         DataTable table = GenerateDataTable("Other COM Component Information");
  594.         Assign(table, "dyy.zipsvr", TestObject("dyy.zipsvr").ToString());
  595.         Assign(table, "hin2.com_iis", TestObject("hin2.com_iis").ToString());
  596.         Assign(table, "Socket.TCP", TestObject("Socket.TCP").ToString());
  597.         return table;
  598.     }
  599.     private DataTable GetSessionInfo()
  600.     {
  601.         DataTable table = GenerateDataTable("Session Information");
  602.         Assign(table, "Session Count", Session.Contents.Count.ToString());
  603.         Assign(table, "Application Count", Application.Contents.Count.ToString());
  604.         return table;
  605.     }
  606.     private DataTable GetRequestHeaderInfo()
  607.     {
  608.         DataTable table = GenerateDataTable("Request Headers");
  609.         foreach (string key in Request.Headers.AllKeys)
  610.         {
  611.             Assign(table, key, Request.Headers[key]);
  612.         }
  613.         return table;
  614.     }
  615.     #endregion
  616.     #region Helper Methods
  617.     private string FormatNumber(ulong value)
  618.     {
  619.         if (value < 4*1024){
  620.             return string.Format("{0} Bytes", value);
  621.         }
  622.         else if (value < (long)4 * 1024 * 1024)
  623.         {
  624.             return string.Format("{0} KB", (value / (double)((long)1024)).ToString("N"));
  625.         }
  626.         else if (value < (long)4 * 1024 * 1024 * 1024)
  627.         {
  628.             return string.Format("{0} MB", (value / (double)((long)1024 * 1024)).ToString("N"));
  629.         }
  630.         else if (value < (long)4 * 1024 * 1024 * 1024 * 1024)
  631.         {
  632.             return string.Format("{0} GB", (value / (double)((long)1024 * 1024 * 1024)).ToString("N"));
  633.         }
  634.         else
  635.         {
  636.             return string.Format("{0} TB", (value / (double)((long)1024 * 1024 * 1024 * 1024)).ToString("N"));
  637.         }
  638.     }
  639.     private DataTable GenerateDataTable(string name)
  640.     {
  641.         DataTable table = new DataTable(name);
  642.         table.Columns.Add("Name", typeof(string));
  643.         table.Columns.Add("Value", typeof(string));
  644.         return table;
  645.     }
  646.     private bool TestObject(string progID)
  647.     {
  648.         try
  649.         {
  650.             Server.CreateObject(progID);
  651.             return true;
  652.         }
  653.         catch (Exception)
  654.         {
  655.             return false;
  656.         }
  657.     }
  658.     private void Assign(DataTable table, string name, string value)
  659.     {
  660.         DataRow row = table.NewRow();
  661.         row["Name"] = name;
  662.         row["Value"] = value;
  663.         table.Rows.Add(row);
  664.     }
  665.     private void LoadInformation(DataTable table)
  666.     {
  667.         DataGrid grid = new DataGrid();
  668.         BoundColumn col;
  669.         col = new BoundColumn();
  670.         col.DataField = "Name";
  671.         col.HeaderText = "Name";
  672.         col.ItemStyle.CssClass = "name";
  673.         grid.Columns.Add(col);
  674.         col = new BoundColumn();
  675.         col.DataField = "Value";
  676.         col.HeaderText = "Value";
  677.         col.ItemStyle.CssClass = "value";
  678.         grid.Columns.Add(col);
  679.         grid.AutoGenerateColumns = false;
  680.         grid.HeaderStyle.CssClass = "header";
  681.         grid.DataSource = new DataView(table);
  682.         grid.DataBind();
  683.         
  684.         
  685.         foreach(DataGridItem item in grid.Items)
  686.         {
  687.             if(item.Cells.Count == 2){
  688.                 TableCell cell = item.Cells[1];
  689.                 //  change true/false style
  690.                 switch (cell.Text.ToLower())
  691.                 {
  692.                     case "true":
  693.                         cell.CssClass = "value_true";
  694.                         break;
  695.                     case "false":
  696.                         cell.CssClass = "value_false";
  697.                         break;
  698.                 }
  699.                 //  wrap <pre> for text contain newline.
  700.                 if (cell.Text.IndexOf(Environment.NewLine) >= 0)
  701.                 {
  702.                     cell.Text = string.Format("<pre>{0}</pre>", cell.Text);
  703.                 }
  704.             }
  705.         }
  706.         
  707.         HtmlGenericControl title = new HtmlGenericControl("h1");
  708.         title.InnerText = Server.HtmlEncode(table.TableName);
  709.         title.Attributes.Add("class", "title");
  710.         HtmlGenericControl div = new HtmlGenericControl("div");
  711.         div.Attributes.Add("class", "section");
  712.         div.Controls.Add(new HtmlGenericControl("p"));
  713.         div.Controls.Add(title);
  714.         div.Controls.Add(grid);
  715.         div.Controls.Add(new HtmlGenericControl("p"));
  716.         divCenter.Controls.Add(div);
  717.     }
  718.     #endregion
  719.     protected void Page_Load(object sender, EventArgs e)
  720.     {
  721.         LoadInformation(GetSystemInfo());
  722.         LoadInformation(GetSystemProcessorInfo());
  723.         LoadInformation(GetSystemMemoryInfo());
  724.         LoadInformation(GetSystemStorageInfo());
  725.         LoadInformation(GetRequestHeaderInfo());
  726.         LoadInformation(GetServerVariables());
  727.         LoadInformation(GetEnvironmentVariables());
  728.         LoadInformation(GetSessionInfo());
  729.         LoadInformation(GetSystemObjectInfo());
  730.         LoadInformation(GetMailObjectInfo());
  731.         LoadInformation(GetUploadObjectInfo());
  732.         LoadInformation(GetGraphicsObjectInfo());
  733.         LoadInformation(GetOtherObjectInfo());
  734.     }
  735. </script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章