1)
private string getIp()
{/*穿过代理服务器取远程用户真实IP地址:*/
if(Request.ServerVariables["HTTP_VIA"]!=null)
return Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
else
return Request.ServerVariables["REMOTE_ADDR"].ToString();
}
Label2.Text =getIp();
HttpBrowserCapabilities bc = new HttpBrowserCapabilities();
bc = Request.Browser;
string xitong ="你的操作系统为";
Label3.Text=xitong+bc.Platform + " 浏览器类型:" + bc.Type;
2)
private string Ip()
if(Request.ServerVariables["HTTP_VIA"]!=null)
{
return Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
return Request.ServerVariables["REMOTE_ADDR"].ToString();
}
Label1.Text =Ip();
3)
public static string GetRealIP()
{
string ip;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
}
else
{
ip = request.UserHostAddress;
}
}
catch (Exception e)
{
throw e;
}
return ip;
}
真实IP
public static string GetViaIP()
{
string viaIp = null;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
viaIp = request.UserHostAddress;
}
}
catch (Exception e)
{
throw e;
}
return viaIp;
得代理IP
如果多级代理不知能不能成功