Guest User

Untitled

a guest
May 20th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. <%@ Page Language="C#" AutoEventWireup="true" %>
  2. <%@ Import Namespace="System" %>
  3. <%@ Import Namespace="System.Diagnostics" %>
  4. <%@ Import Namespace="System.Text" %>
  5. <%@ Import Namespace="System.DirectoryServices" %>
  6. <%@ Import Namespace="System.Collections.Generic" %>
  7.  
  8.  
  9. <script type="text/C#" runat="server">
  10.  
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13. if (!IsPostBack)
  14. {
  15. populateIIS();
  16. }
  17. }
  18.  
  19. private void populateIIS()
  20. {
  21. StringBuilder sb = new StringBuilder();
  22. sb.AppendFormat("Server: {0} Username: {1}<br/>", Environment.MachineName.ToString(), Environment.UserName.ToString());
  23. try
  24. {
  25. TimeSpan span = TimeSpan.FromSeconds(Convert.ToDouble(getCounter("Web Service", "Service Uptime", "_Total")));
  26. sb.Append(string.Concat(new object[] { "IIS Running - Uptime : ", span.Days, " Days, ", span.Hours, " Hours, ", span.Minutes, " Min <br/>" }));
  27. }
  28. catch { }
  29. sb.AppendFormat("Current Anonymous users: {0}<br/>", getCounter("Web Service", "Current Anonymous Users", "_Total"));
  30. sb.AppendFormat("Current Connections: {0}<br/>", getCounter("Web Service", "Current Connections", "_Total"));
  31. sb.AppendFormat("Max Connections: {0}<br/>", getCounter("Web Service", "Maximum Connections", "_Total"));
  32. sb.AppendFormat("Memory, Available MBytes: {0}<hr/>", getCounter("Memory", "Available MBytes", ""));
  33. sb.AppendFormat("ASP.NET Request Wait Time: {0}<br/>", getCounter("ASP.NET", "Request Wait Time", ""));
  34.  
  35. sb.AppendFormat("ASP.NET Application Anonymous Requests: {0}<br/>", getCounter("ASP.NET Applications", "Anonymous Requests", "__Total__"));
  36. sb.AppendFormat("ASP.NET Sessions Active: {0}<br/>", getCounter("ASP.NET Applications", "Sessions Active", "__Total__"));
  37. sb.AppendFormat("ASP.NET Sessions Total: {0}<br/>", getCounter("ASP.NET Applications", "Sessions Total", "__Total__"));
  38. sb.AppendFormat("ASP.NET Applications Running: {0}<hr/>", getCounter("ASP.NET v2.0.50727", "Applications Running", ""));
  39.  
  40. sb.Append("IIS Apps <br/>");
  41. foreach (string s in getIISApps())
  42. { sb.AppendFormat("{0}", s);}
  43.  
  44. lblText.Text = sb.ToString();
  45. }
  46.  
  47. public static string getCounter(string a, string b, string c)
  48. {
  49. string countervalue;
  50. try
  51. {
  52. string str = string.Empty;
  53. PerformanceCounter counter = new PerformanceCounter(a, b);
  54. counter.InstanceName = c;
  55. str = counter.NextValue().ToString();
  56. counter.Dispose();
  57. counter.Close();
  58. countervalue = str;
  59. }
  60. catch (Exception exception)
  61. {
  62. throw exception;
  63. }
  64. return countervalue;
  65. }
  66.  
  67.  
  68. private List<string> getIISApps()
  69. {
  70. List<string> sites = new List<string>();
  71.  
  72. DirectoryEntry entry = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");
  73. try
  74. {
  75. foreach (DirectoryEntry entry2 in entry.Children)
  76. {
  77. if (entry2.SchemaClassName == "IIsWebServer")
  78. {
  79. foreach (DirectoryEntry entry3 in entry2.Children)
  80. {
  81. string binding;
  82. if (!(entry3.SchemaClassName == "IIsWebVirtualDir"))
  83. {
  84. continue;
  85. }
  86.  
  87. if (entry2.Properties["ServerBindings"].Value.ToString() == "System.Object[]")
  88. {
  89. binding = "All Unassigned";
  90. }
  91. else
  92. {
  93. binding = entry2.Properties["ServerBindings"].Value.ToString();
  94. }
  95. sites.Add(string.Format("name: {0} - binding: {1}<br/>", entry2.Properties["ServerComment"].Value.ToString(), binding));
  96. }
  97.  
  98. }
  99. }
  100. }
  101. catch (Exception ex)
  102. {
  103. throw ex;
  104. }
  105. return sites;
  106. }
  107.  
  108.  
  109.  
  110. </script>
  111. <asp:Label ID="lblText" runat="server" />
Add Comment
Please, Sign In to add comment