下面的代碼來源於網絡,回歸於網絡,有需要的話直接COPY過去用就是了。
protected void Page_Load(object sender, EventArgs e)
{
this.lblIP.Text = Request.UserHostAddress.ToString();//獲取IP
string strSysVersion = "其他";
string strAgentInfo = Request.ServerVariables["HTTP_USER_AGENT"];
if (strAgentInfo.Contains("NT 5.2"))
{
strSysVersion = "Windows 2003";
}
else if (strAgentInfo.Contains("NT 5.1"))
{
strSysVersion = "Windows XP";
}
else if (strAgentInfo.Contains("NT 5"))
{
strSysVersion = "Windows 2000";
}
else if (strAgentInfo.Contains("NT 4.9"))
{
strSysVersion = "Windows ME";
}
else if (strAgentInfo.Contains("NT 4"))
{
strSysVersion = "Windows NT4";
}
else if (strAgentInfo.Contains("NT 98"))
{
strSysVersion = "Windows 98";
}
else if (strAgentInfo.Contains("NT 95"))
{
strSysVersion = "Windows 95";
}
else if (strSysVersion.ToLower().Contains("Mac"))
{
strSysVersion = "Mac";
}
else if (strSysVersion.ToLower().Contains("unix"))
{
strSysVersion = "UNIX";
}
else if (strSysVersion.ToLower().Contains("Linux"))
{
strSysVersion = "Linux";
}
else if (strSysVersion.Contains("SunOS"))
{
strSysVersion = "SunOS";
}
this.lblOpSys.Text = strSysVersion;
}
獲取穿過代理服務器獲取完成用戶真實IP地址。
1
private string getIp()
2 { /*穿過代理服務器取遠程用戶真實IP地址:*/
3 if(Request.ServerVariables["HTTP_VIA"]!=null)
4 return Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
5 else
6 return Request.ServerVariables["REMOTE_ADDR"].ToString();
7 }
8
Label2.Text =getIp();
9
HttpBrowserCapabilities bc = new HttpBrowserCapabilitIEs();
10
bc = Request.Browser;
11
string xitong ="你的操作系統為";
12
Label3.Text=xitong+bc.Platform + " 浏覽器類型:" + bc.Type;