ASP.NET获取客户端IP地址、系统版本、浏览器版本

ASP.NET获取客户端IP地址、系统版本、浏览器版本

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.Data.SqlClient;

public partial class WebStart : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}

//获取浏览器版本号
public string getBrowser() {
string browsers;
HttpBrowserCapabilities bc = HttpContext.Current.Request.Browser;
string aa = bc.Browser.ToString();
string bb = bc.Version.ToString();
browsers = aa + bb;
return browsers;
}

//获取客户端IP地址
public string getIP()
{
string result = String.Empty;
result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
if (null == result || result == String.Empty)
{
return "0.0.0.0";
}
return result;
}

//获取操作系统版本号
public static string SystemCheck()
{
string Agent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];

if (Agent.IndexOf("NT 4.0") > 0)
{
return "Windows NT ";
}
else if (Agent.IndexOf("NT 5.0") > 0)
{
return "Windows 2000";
}
else if (Agent.IndexOf("NT 5.1") > 0)
{
return "Windows XP";
}
else if (Agent.IndexOf("NT 5.2") > 0)
{
return "Windows 2003";
}
else if (Agent.IndexOf("NT 6.0") > 0)
{
return "Windows Vista";
}
else if (Agent.IndexOf("WindowsCE") > 0)
{
return "Windows CE";
}
else if (Agent.IndexOf("NT") > 0)
{
return "Windows NT ";
}
else if (Agent.IndexOf("9x") > 0)
{
return "Windows ME";
}
else if (Agent.IndexOf("98") > 0)
{
return "Windows 98";
}
else if (Agent.IndexOf("95") > 0)
{
return "Windows 95";
}
else if (Agent.IndexOf("Win32") > 0)
{
return "Win32";
}
else if (Agent.IndexOf("Linux") > 0)
{
return "Linux";
}
else if (Agent.IndexOf("SunOS") > 0)
{
return "SunOS";
}
else if (Agent.IndexOf("Mac") > 0)
{
return "Mac";
}
else if (Agent.IndexOf("Linux") > 0)
{
return "Linux";
}
else if (Agent.IndexOf("Windows") > 0)
{
return "Windows";
}
return "未知类型";
}
}

参考资料

柏拉涂
http://hi.baidu.com/huangenci/blog/item/a240299bb39a53bcc8eaf47b.html

    ASP.NET获取客户端IP地址、系统版本、浏览器版本_第1张图片
职业规划网    网购从这里开始 ( 物美价廉还等什么?!!! )    

2012夏装新款薄纱拼接性感包臀显瘦party宴会礼服连衣裙子女配胸
2012夏装新款韩版时尚雪纺皇冠ZUMA正品女装小衫短上衣
2条包邮 春夏 韩版 糖果色运动休闲松紧腰大码短裤 沙滩裤 热裤
简约字母韩版百搭露肩小性感随意范儿中长款长袖T恤
春装 新款 女装豹纹丝绒百搭裙包臀裙打底裙迷你阔摆裙短裙半
秋水伊人2012新款夏装连衣裙122102023专柜正品代购女裙子夏季新
秋水伊人2012新款夏装连衣裙122102017专柜正品代购女裙子送礼品
2012夏季新款大码女装裤夏女七九分弹力韩版潮显瘦打底裤包邮薄款
春装2012新款 蕴熙韩版女装 修身款打底衫 女式圆领长袖T恤 包邮

你可能感兴趣的:(asp.net)