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.
strDNS =
Dns.GetHostName();Session[
"UserIP"] = Dns.GetHostEntry(strDNS).AddressList[0].ToString();I believe this will retreive the Server's IP address.
strDNS =
HttpWorkerRequest.GetRemoteAddress.ToString();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

How to get a client's IP Address
BillW
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
Alias
strDNS = Dns.GetHostName();
Session["UserIP"] = Dns.GetHostEntry(strDNS).AddressList[0].ToString();
strDNS = HttpWorkerRequest.GetRemoteAddress().ToString();
tomatgdd
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
Billaboard
If it's a web app running from asp.net, wouldn't "Context.Request.UserHostAddress" get the IP of the client connecting to it Perhaps I'm misinterpreting what the question was
mik_mihai
IPAddress[] addresses = Dns.GetHostByName( "MACHINE1" ).AddressList;
foreach( IPAddress address in addresses )
{
Console.WriteLine( address.ToString() );
}
Priyanga Karunathilake
Athan
Utsav Kedia