获取服务器相关信息

1.通过下面代码可以获取服务器的一些相关信息,例如IP,系统,端口

获取服务器相关信息_第1张图片

相应代码:

  需要引用using System.Net;命名空间

 

 string name = Dns.GetHostName();
          IPHostEntry myip=Dns.GetHostEntry(name);
          foreach (IPAddress ip in myip.AddressList)
          {
              if (ip.AddressFamily.ToString() == "InterNetwork")
                  ///InterNetwork为ip4地址,InterNetworkV6为ip6地址
                    this.lb_ip.InnerText = ip.ToString();
          }
        //获取名称
        string pcname = Dns.GetHostName();
        this.lb_server_name.InnerText = Dns.GetHostName();
        //iis
        this.lb_iis_version.InnerText = Request.ServerVariables["SERVER_SOFTWARE"];
        //时间
        this.lb_time.InnerText = DateTime.Now.ToString("yyyy-MM-dd");
        //路径
        this.lb_path.InnerText = Server.MapPath(Request.ServerVariables["script_name"]);
        //端口
        this.lb_port.InnerText = Request.ServerVariables["SERVER_PORT"];
        //系统
        this.lb_system.InnerText = Environment.OSVersion.Platform.ToString() + " " + Environment.OSVersion.Version.ToString();
        //超时
        this.lb_overtime.InnerText = Server.ScriptTimeout.ToString();


你可能感兴趣的:(系统,获取IP)