Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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 ....
 
Share this answer
 
v2
Comments
Amol Lendave 3-Dec-13 3:58am    
Ya i have tried it gives me ip of proxy i don't want it, i just want ip of local machine.

I google it but still i didn't get propper solution.
Amol Lendave 3-Dec-13 4:26am    
Finally i got LoopBack ip i.e 127.0.0.1 .
Can i restrict to retrieving machines ip instead of loopback ip.
See this answer posted by me just before few hours : Get Client IP Address[^]
 
Share this answer
 
can you tried below code
C#
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;
}
 
Share this answer
 
v3
C#
public static string GetClientIP()
        {
            try
            {
                string Ip = string.Empty;
                string ipList = HttpContext.Current.Request.ServerVariables["HTTP_X_CLUSTER_CLIENT_IP"];
                if (!string.IsNullOrEmpty(ipList))
                {
                    Ip = ipList.Split(',')[0];
                }
                else
                {
                    Ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }

                if (Ip.Equals("127.0.0.1"))
                {
                    Ip = Dns.GetHostAddresses(Dns.GetHostName()).GetValue(0).ToString();
                }
                return Ip;
            }
            catch
            {
                throw;
            }
        }



You may think that why you are checking loopback (127.0.0.1).
If i am working on same machine where this app deployed then it will give me loopback insted of actual IP.



Is it right way to check loopback?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900