Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys,

i'm tried hard to get, client's machine ip address,

I have a site on domain server, where i have to get user login details,
where i'm fetching user(Client) machine ip address,

but i'm getting same ip address for all users, who is logging from different networks.

Code what i tried so far:

C#
public string GetIP4Address()
        {

            IPHostEntry host;
            string localIp = "?";
            string hostName = Dns.GetHostName();
            host = Dns.GetHostEntry(hostName);
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily.ToString() == "InterNetwork")
                {
                    localIp = ip.ToString();
                }
                //localIp += " " + ip.AddressFamily.ToString() + " ";
            }
            return localIp;
        }



Can anyone plzzz help me...

Thanks
Posted

C#
HttpContext.Current.Request.UserHostAddress
 
Share this answer
 
Comments
abdul subhan mohammed 23-May-14 6:36am    
its working on localhost, but when i upload on my domain its prompting error message...
Kornfeld Eliyahu Peter 23-May-14 8:49am    
What error?
abdul subhan mohammed 24-May-14 12:13pm    
public string GetIP4Address()
{

IPHostEntry host;
string localIp = "?";
string hostName = Dns.GetHostName();
host = Dns.GetHostEntry("UR LINE HERE");// I have added ur line here
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily.ToString() == "InterNetwork")
{
localIp = ip.ToString();
}
//localIp += " " + ip.AddressFamily.ToString() + " ";
}
return localIp;
}

plz let me know, whether i have added ur line at the correct place or not...

thnx
 
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