Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I have a MVC Web Application, This Application is hosted in a public server.

I needs to get the local machine Ipaddress(not the network public ip) of every user who uses this site in their machines...

How can i achieve this ?..


Thanks
Magesh.M
Posted
Comments
F-ES Sitecore 30-Jun-15 4:29am    
You can't get this in your server code, you'll need some component on the client like an activex component or java applet that reads the ip address and injects it into a hidden field on the page for you to then send to your site.

This is one of those questions that is asked a lot so if you google you should find a pre-written component that does this.
Magesh M N 30-Jun-15 7:59am    
could you please provide the pre-written component for this purpose or the link for refer this...

1 solution

Try this.

C#
public static string GetIPAddress()
   {
       IPHostEntry host;
       string localIP = "?";
       host = Dns.GetHostEntry(Dns.GetHostName());
       foreach (IPAddress ip in host.AddressList)
       {
           if (ip.AddressFamily == AddressFamily.InterNetwork)
           {
               localIP = ip.ToString();
           }
       }
       return localIP;
   }
 
Share this answer
 
Comments
Magesh M N 30-Jun-15 8:07am    
I tried this, but it returns the ip address of the hosted machine..
praveenlob7 30-Jun-15 9:19am    
context.Request.ServerVariables["REMOTE_HOST"]

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