如何获取用户机器的IP地址。

问题描述:

我有一个Web应用程序,我需要在获取IP时跟踪用户机器的ip以获取安全性。当该机器与代理服务器相关时,我无法获得本地机器ip。我想获得本地机器的IP,即使它有代理服务器。

如何获得该IP可以帮助我吗?





比你提前

I have one web application in that i need to track the ip of user's machine for security rision at the time of getting ip i'm not able to get local machine ip when that machin is related with proxy server. I want to get ip of local machine even it is having proxy server.
How to get that ip can any one assist me?


Than you in advance

你做过什么只是Google it and try Something如果你仍然面对此处发布的任何特定问题请尝试使用 HttpRequest.UserHostAddress Property ... 。
Have You tried anything just Google it and try Something If still you are facing any specific issue post here Try Using HttpRequest.UserHostAddress Property ....


在几个小时之前看到我发布的这个答案:获取客户端IP地址 [ ^ ]
See this answer posted by me just before few hours : Get Client IP Address[^]


你可以尝试下面的代码

can you tried below code
protected void GetUser_IP()
{
    string VisitorsIPAddr = string.Empty;
    if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
    {
        VisitorsIPAddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
    }
    else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
    {
        VisitorsIPAddr = HttpContext.Current.Request.UserHostAddress;
    }
    uip.Text = "Your IP is" + VisitorsIPAddr;
}