关于探针的研究

CS代码:

 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.ComponentModel;
using Microsoft.Win32;
using System.IO;
using System.Management;
using System.Diagnostics;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //获得本地计算机信息
        if (!IsPostBack)
        {
            /// <summary>
            /// 取应用程序路径
            /// </summary>

            lbServerName.Text = "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath;
            //lbIp.Text = Request.ServerVariables["LOCAl_ADDR"];
            //lbDomain.Text = Request.ServerVariables["SERVER_NAME"].ToString();
            //lbPort.Text = Request.ServerVariables["Server_Port"].ToString();
            //lbIISVer.Text = Request.ServerVariables["Server_SoftWare"].ToString();
            //lbPhPath.Text = Request.PhysicalApplicationPath;
            //lbOperat.Text = Environment.OSVersion.ToString();
            //lbSystemPath.Text = Environment.SystemDirectory.ToString();
            //lbTimeOut.Text = (Server.ScriptTimeout/1000).ToString() + "秒";
            //lbLan.Text =  CultureInfo.InstalledUICulture.EnglishName;
            //lbAspnetVer.Text = string.Concat(new object[] { Environment.Version.Major, ".", Environment.Version.Minor, Environment.Version.Build, ".", Environment.Version.Revision });
            //lbCurrentTime.Text = DateTime.Now.ToString();

            //RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE/Microsoft/Internet Explorer/Version Vector");
            //lbIEVer.Text = key.GetValue("IE", "未检测到").ToString();
            //lbServerLastStartToNow.Text = ((Environment.TickCount / 0x3e8)/60).ToString() + "分钟";

            //string[] achDrives = Directory.GetLogicalDrives();
            //for (int i = 0; i < Directory.GetLogicalDrives().Length - 1; i++)
            //{
            //    lbLogicDriver.Text = lbLogicDriver.Text + achDrives[i].ToString();
            //}

            ManagementClass diskClass = new ManagementClass("NUMBER_OF_PROCESSORS");
            //lbCpuNum.Text = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS").ToString();
            //lbCpuType.Text = Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER").ToString();
            //lbMemory.Text = (Environment.WorkingSet / 1024).ToString()+ "M";
            //lbMemoryPro.Text = ((Double)GC.GetTotalMemory(false) / 1048576).ToString("N2") + "M";
            //lbMemoryNet.Text = ((Double)Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2") + "M";
            //lbCpuNet.Text = ((TimeSpan)Process.GetCurrentProcess().TotalProcessorTime).TotalSeconds.ToString("N0");
            //lbSessionNum.Text = Session.Contents.Count.ToString();
            //lbSession.Text = Session.Contents.SessionID;
            //lbUser.Text = Environment.UserName;

            //lbTest.Text = Server.HtmlEncode(Request.ServerVariables["Server_SoftWare"].ToString());
            WebService2 web = new WebService2();
            web.HelloWorld();
            //int iy = 1;

        }
    }
    //操作远程计算机
    protected void Button1_Click(object sender, EventArgs e)
    {


        long mb = 1048576;

        //1024x1024

        //设定生成的WMI所需的所有设置

        System.Management.ConnectionOptions Conn = new ConnectionOptions();
        Conn.EnablePrivileges = true;
        //设定用于WMI连接操作的用户名

        Conn.Username = "Administrator";

        //设定用户的口令

        Conn.Password = "";

        //设定用于执行WMI操作的范围

        System.Management.ManagementScope Ms = new ManagementScope("192.168.168.16//root//cimv2", Conn);

        System.Management.ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem");

        ManagementObjectSearcher query1 = new ManagementObjectSearcher(Ms,oq);
        ManagementObjectCollection queryCollection1 = query1.Get();
       

        foreach ( ManagementObject mo in queryCollection1 )
        {
            string[] ss={""};
            //mo.InvokeMethod("ShutDown", ss);
           
               
            Response.Write(mo.ToString());
           
        }
    }
}

 

 


        //try
        //{

        //    //连接到实际操作的WMI范围

        //    Ms.Connect();

        //    //设定通过WMI要查询的内容

        //    ObjectQuery Query = new ObjectQuery("select FreeSpace ,Size ,Name from Win32_LogicalDisk where DriveType=3");


        //    //WQL语句,设定的WMI查询内容和WMI的操作范围,检索WMI对象集合

        //    ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Ms, Query);

        //    //异步调用WMI查询

        //    ManagementObjectCollection ReturnCollection = Searcher.Get();

        //    double free = 0;

        //    double use = 0;

        //    double total = 0;

        //    //listBox1.Items.Clear();

        //    //通过对产生的WMI的实例集合进行检索,获得硬盘信息

        //    foreach (ManagementObject Return in ReturnCollection)
        //    {
        //        Label1.Text = "磁盘名称:" + Return["Name"].ToString();
        //        //listBox1.Items.Add("磁盘名称:" + Return["Name"].ToString());

        //        //获得硬盘的可用空间

        //        free = Convert.ToInt64(Return["FreeSpace"]) / mb;

        //        //获得硬盘的已用空间

        //        use = (Convert.ToInt64(Return["Size"]) - Convert.ToInt64(Return["FreeSpace"])) / mb;

        //        //获得硬盘的合计空间

        //        total = Convert.ToInt64(Return["Size"]) / mb;

        //        //listBox1.Items.Add ( " 总计:"+ total.ToString ( ) + "MB";

        //    }
        //}
        //catch (Exception ee)
        //{

        //    //MessageBox.Show("连接" + textBox1.Text + "出错,出错信息为:" + ee.Message, "出现错误!");

        //}


    //}
//}

 

ASPX代码:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Asp.net探针 |— 51aspx.com</title>
     <style type="text/css">
  BODY { FONT-SIZE: 12px; COLOR: #000000 }
  TABLE { FONT-SIZE: 12px; COLOR: #000000 }
  TD { FONT-SIZE: 12px; COLOR: #000000 }
  FORM { PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px }
  TD TD { PADDING-LEFT: 12px }
  A { COLOR: #000090 }
  A:hover { COLOR: #ff3333 }
  .InputTxt { BORDER-RIGHT: #333333 1px solid; BORDER-TOP: #333333 1px solid; FONT-SIZE: 12px; BORDER-LEFT: #333333 1px solid; WIDTH: 120px; BORDER-BOTTOM: #333333 1px solid; HEIGHT: 18px }
  .Button { BORDER-RIGHT: #333333 1px solid; BORDER-TOP: #333333 1px solid; FONT-SIZE: 12px; BACKGROUND: #ffffff; BORDER-LEFT: #333333 1px solid; WIDTH: 32px; BORDER-BOTTOM: #333333 1px solid; HEIGHT: 16px }
  .TrHead { FONT-WEIGHT: 600; FONT-SIZE: 12px; BACKGROUND: #339900; COLOR: #ffffff; HEIGHT: 28px; TEXT-ALIGN: center }
  </style>
</head>
<body>
    <form id="form1" runat="server">
   <table width="100%" align="center" border="0">
    <tr>
     <td style="FONT-WEIGHT: 600; FONT-SIZE: 16px; COLOR: #339900; height: 11px;" align="center"><a href="http://www.51aspx.com" target="_blank">
     <h1>
                        Asp.Net
       探针</h1>
     </a> </td>
    </tr>
   </table>
   <table style="FONT-SIZE: 12px; COLOR: black; FONT-FAMILY: Verdana, Tahoma; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: whitesmoke"
    borderColor="#666666" cellSpacing="0" width="760" align="center" bgColor="#eeeeee"
    border="1">
    <tr>
     <td align="center" style="width: 747px">
      <table style="BORDER-COLLAPSE: collapse" borderColor="#ffffff" cellSpacing="0" width="95%"
       align="center" border="1">
     <tr>
        <td class="TrHead" colSpan="2" style="HEIGHT: 21px">服务器基本信息</td>
       </tr>
       <tr>
        <td width="38%" align="left" style="height: 29px">服务器计算机名</td>
        <td align="left" style="height: 29px">
                              <asp:Label ID="lbServerName" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td height="26" align="left">服务器IP地址</td>
        <td align="left">
                              <asp:Label ID="lbIp" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td height="26" align="left">服务器域名</td>
         <td align="left"><asp:Label ID="lbDomain" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td height="27" align="left" style="HEIGHT: 27px">服务器端口</td>
         <td align="left" style="HEIGHT: 27px">                                    <asp:Label ID="lbPort" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td height="26" align="left">服务器IIS版本</td>
        <td align="left">
                              <asp:Label ID="lbIISVer" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td height="24" align="left" style="HEIGHT: 24px">
                                    本文件所在文件夹</td>
        <td align="left" style="HEIGHT: 24px">
                              <asp:Label ID="lbPhPath" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td height="26" align="left">服务器操作系统</td>
        <td align="left">
                              <asp:Label ID="lbOperat" runat="server"></asp:Label></td>
        </tr>
                            <tr>
                                <td height="26" align="left">
                                    系统所在文件夹</td>
                                <td align="left">
                              <asp:Label ID="lbSystemPath" runat="server"></asp:Label></td>
                          </tr>
       <tr>
        <td height="26" align="left">服务器脚本超时时间</td>
        <td align="left">
                              <asp:Label ID="lbTimeOut" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td height="26" align="left">服务器的语言种类</td>
        <td align="left">
                              <asp:Label ID="lbLan" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td height="27" align="left" style="HEIGHT: 27px">.NET Framework 版本</td>
        <td align="left" style="HEIGHT: 27px">
                              <asp:Label ID="lbAspnetVer" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td align="left" style="height: 29px">服务器当前时间</td>
        <td align="left" style="height: 29px">
                              <asp:Label ID="lbCurrentTime" runat="server"></asp:Label></td>
        </tr>
                            <tr>
                                <td height="26" align="left">
                                    服务器IE版本</td>
                                <td align="left">
                              <asp:Label ID="lbIEVer" runat="server"></asp:Label></td>
                          </tr>
       <tr>
        <td height="26" align="left">服务器上次启动到现在已运行</td>
        <td align="left">
                              <asp:Label ID="lbServerLastStartToNow" runat="server"></asp:Label></td>
        </tr>
       <tr>
        <td width="38%" align="left" style="HEIGHT: 8px">逻辑驱动器</td>
        <td align="left" style="HEIGHT: 8px">
                              <asp:Label ID="lbLogicDriver" runat="server"></asp:Label></td>
        </tr>
       <TR>
        <TD height="26" align="left">CPU 总数</TD>
        <TD align="left">
                              <asp:Label ID="lbCpuNum" runat="server"></asp:Label></TD>
        </TR>
                            <tr>
                                <td height="26" align="left">
                                    CPU 类型</td>
                                <td align="left">
                              <asp:Label ID="lbCpuType" runat="server"></asp:Label></td>
                          </tr>
                            <tr>
                                <td align="left" style="height: 29px">
                                    虚拟内存</td>
                                <td align="left" style="height: 29px">
                              <asp:Label ID="lbMemory" runat="server"></asp:Label></td>
                          </tr>
                            <tr>
                                <td align="left" style="height: 29px">
                                    当前程序占用内存</td>
                                <td align="left" style="height: 29px">
                              <asp:Label ID="lbMemoryPro" runat="server"></asp:Label></td>
                          </tr>
                            <tr>
                                <td align="left" style="height: 29px">
                                    Asp.net所占内存</td>
                                <td align="left" style="height: 29px">
                              <asp:Label ID="lbMemoryNet" runat="server"></asp:Label></td>
                          </tr>
                            <tr>
                                <td align="left" style="height: 29px">
                                    Asp.net所占CPU</td>
                                <td align="left" style="height: 29px">
                              <asp:Label ID="lbCpuNet" runat="server"></asp:Label></td>
                          </tr>
                            <tr>
                                <td align="left" style="height: 29px">
                                    当前Session数量</td>
                                <td align="left" style="height: 29px">
                              <asp:Label ID="lbSessionNum" runat="server"></asp:Label></td>
                          </tr>
                            <tr>
                                <td align="left" style="height: 29px">
                                    当前SessionID</td>
                                <td align="left" style="height: 29px">
                              <asp:Label ID="lbSession" runat="server"></asp:Label></td>
                          </tr>
                            <tr>
                                <td align="left" style="height: 29px">
                                    当前系统用户名</td>
                                <td align="left" style="height: 29px">
                              <asp:Label ID="lbUser" runat="server"></asp:Label></td>
                          </tr>
                            <tr>
                                <td align="left" style="height: 29px">
                                    当前测试</td>
                                <td align="left" style="height: 29px">
                                    <asp:Label ID="lbTest" runat="server" ></asp:Label></td>
                            </tr>
      </table>
       <BR>
       <table width="95%" border="0">
    <tr>
     <td align="center" class="TrHead">
                    Asp.net探针</tr>
   </table>
                        &nbsp;
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        <asp:Label ID="Label1" runat="server" Text="Label" Width="253px"></asp:Label>
                        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td> </tr> </table>

    </form>
</body>
</html>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值