I have a web app that need to get the client's IP Address. I have attempted several different methods without success. I have pasted the code below.
Session["UserIP"] = Dns.GetHostEntry(strDNS).AddressList.ToString();
I believe this will retreive the Server's IP address.
I believe something along these lines should work but VS 2005 erros on build saying "Cannot convert method group 'GetRemoteAddress' to non-delegatetype 'object'.' How can I accomplish this task?
Sorry, I have been out of the office. I have attempted to change the code but I continue to get the error on build "Error 1 An object reference is required for the nonstatic field, method, or property 'System.Web.HttpWorkerRequest.GetRemoteAddress()'"
WHat does this mean and How can i fix it?
Sorry, posted the wrong code. Don't know what happend but here is the code i want to post:
IPAddress addresses = Dns.GetHostByName( "MACHINE1" ).AddressList;
foreach( IPAddress address in addresses )
Console.WriteLine( address.ToString() );
That is great, I thing this gets the same infromation the code I posted gets. Doesn't the 'GetHostName' getting the server name and the IPAddress of the Server?
Shouldn't I be using 'HttpWorkerRequest.GetRemoteAddress' to get the client IPAddress and How would I do that?
If the client has a private IP... the web server must be inside the client's network to retrieve the private IP. If you're not in the network, you'll only get the visible public IP of the router that's actually connecting to the server. The client would have to send it's internal IP in order for you to get it.