using System;
using System.Data;
using System.Configuration;
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.Net;
using System.Text;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//获取URL地址
string url = Request.Url.ToString();
txtUrl.Text = url;
//获取IP地址
string ips= Request.UserHostAddress.ToString();
txtIp.Text = ips;
//浏览器
string fr = Request.Browser.Type.ToString();
// txtbrows.Text = fr;
string cp ;//= Request.UserAgent.ToString()
cp=GetOSNameByUserAgent(Request.UserAgent.ToString());
txtcp.Text = cp;
//浏览器
this.txtbrows.Text = Request.Browser.ClrVersion.ToString();
// txtUrl.Text = Request.ServerVariables["http_referer"];
}
protected void btnGet_Click(object sender, EventArgs e)
{
txtUrl.Text = Request.ServerVariables["http_referer"];//ServerViables["http_referer"];
string strurl= txtUrl.Text.ToString(); //欲获取的网页地址 要 http://
WebClient myWebClient = new WebClient(); //创建WebClient实例myWebClient
//获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。
myWebClient.Credentials = CredentialCache.DefaultCredentials;
// Request.ServerVariables("HTTP_HOST");
//从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
byte[] pagedata = myWebClient.DownloadData(@strurl);
string result = Encoding.Default.GetString(pagedata); //如果获取网站页面采用的是GB2312,则使用这句
//string result = Encoding.UTF8.GetString(pagedata); //如果获取网站页面采用的是UTF-8,则使用这句
Response.Write(result); //在WEB页中显示获取的内容
Panel1.Visible = false;
}
/// <summary>
/// 根据 User Agent 获取操作系统名称
/// </summary>
private string GetOSNameByUserAgent(string userAgent)
{
string osVersion = "未知";
if (userAgent.Contains("NT 6.0"))
{
osVersion = "Windows Vista/Server 2008";
}
else if (userAgent.Contains("NT 5.2"))
{
osVersion = "Windows Server 2003";
}
else if (userAgent.Contains("NT 5.1"))
{
osVersion = "Windows XP";
}
else if (userAgent.Contains("NT 5"))
{
osVersion = "Windows 2000";
}
else if (userAgent.Contains("NT 4"))
{
osVersion = "Windows NT4";
}
else if (userAgent.Contains("Me"))
{
osVersion = "Windows Me";
}
else if (userAgent.Contains("98"))
{
osVersion = "Windows 98";
}
else if (userAgent.Contains("95"))
{
osVersion = "Windows 95";
}
else if (userAgent.Contains("Mac"))
{
osVersion = "Mac";
}
else if (userAgent.Contains("Unix"))
{
osVersion = "UNIX";
}
else if (userAgent.Contains("Linux"))
{
osVersion = "Linux";
}
else if (userAgent.Contains("SunOS"))
{
osVersion = "SunOS";
}
return osVersion;
}