Copy codeThe Code is as follows:
/// <Summary>
/// Obtain the user's operating system information
/// </Summary>
/// <Returns> </returns>
Public string GetUserOS ()
{
String strSysVersion = "other ";
HttpRequest Request = HttpContext. Current. Request;
String strAgentInfo = Request. ServerVariables ["HTTP_USER_AGENT"];
If (strAgentInfo. Contains ("NT 6.0 "))
{
StrSysVersion = "Windows Vista ";
}
Else 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 ";
}
Return strSysVersion;
}
/// <Summary>
/// Obtain the browser type and version of the Client
/// </Summary>
/// <Returns> </returns>
Public string GetUserBrowser ()
{
String strBrowser = "other ";
HttpRequest Request = HttpContext. Current. Request;
String strAgentInfo = Request. ServerVariables ["HTTP_USER_AGENT"];
If (Regex. IsMatch (strAgentInfo, "MSIE ([// d] //. [// d])", RegexOptions. IgnoreCase | RegexOptions. Compiled ))
{
StrBrowser = Regex. Match (strAgentInfo, "MSIE ([// d] //. [// d])"). Result ("IE: $1 ");
}
Else if (Regex. IsMatch (strAgentInfo, "Opera ([// d] //. [// d])", RegexOptions. IgnoreCase | RegexOptions. Compiled ))
{
StrBrowser = Regex. Match (strAgentInfo, "Opera ([// d] //. [// d])"). Result ("Opera: $1 ");
}
Else if (Regex. IsMatch (strAgentInfo, "Opera // ([// d] //. [// d])", RegexOptions. IgnoreCase | RegexOptions. Compiled ))
{
StrBrowser = Regex. match (strAgentInfo, "Opera // ([// d] //. [// d]) "). result ("Opera: $1 ");
}
Else if (Regex. IsMatch (strAgentInfo, "Firefox // ([// d] //. [// d])", RegexOptions. IgnoreCase | RegexOptions. Compiled ))
{
StrBrowser = Regex. match (strAgentInfo, "Firefox /// ([// d] //. [// d]) "). result ("Firefox: $1 ");
}
Return strBrowser;
}
# Region GetIP ()
/// <Summary>
/// Obtain the IP address
/// </Summary>
/// <Returns> </returns>
Public string GetIP ()
{
String uip = "";
If (HttpContext. Current. Request. ServerVariables ["HTTP_VIA"]! = Null)
{
Uip = HttpContext. Current. Request. ServerVariables ["HTTP_X_FORWARDED_FOR"]. ToString ();
}
Else
{
Uip = HttpContext. Current. Request. ServerVariables ["REMOTE_ADDR"]. ToString ();
}
Return uip;
}
# Endregion