如何获取客户端的IP地址???
目前在js中用rerquest.getRemoteAddr(),可以获取客户端的ip.
但如果用户使用了代理的话,那么它只能取得代理服务器的ip,却不能获得客户的真实 ip.
哪为高手能告诉我获取用户真实ip的方法?
------解决方案--------------------using System;
using System.Web;
namespace shunxu.Func
{
/// <summary>
/// 获取IP return string
/// </summary>
/// <param name= "_request "> HttpRequest对象 </param>
/// <returns> IP地址 </returns>
public class IPGET
{
public IPGET()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 获取浏览器IP方法
public static string ReStr(HttpRequest _request)
{
string user_IP = null;
string HTTP_VIA = null;
try
{
HTTP_VIA = _request.ServerVariables[ "HTTP_VIA "].ToString();
}
catch
{
HTTP_VIA = null;
}
try
{
if (HTTP_VIA != null)
{
user_IP = _request.ServerVariables[ "HTTP_X_FORWARDED_FOR "].ToString();
}
else
{
user_IP = _request.ServerVariables[ "REMOTE_ADDR "].ToString();
}
}
catch
{
user_IP = _request.UserHostAddress.ToString();
}
return user_IP;
}
#endregion
}
希望对你有用