Visual Studio .NET - Difference between the three Request.ServerVariables["Remote_ADDR"], Request.UserHostAddress, and Request.UserHostName?

Asked By A S on 28-Dec-06 10:23 AM

I want to get user's ip addresses and their online services provider's name. How do we do that? Is there any way to find out if user is coming back to the website lets say after a week from using same computer from ip address since ip addresses are dynamic?

what is the difference between

Request.ServerVariables["REMOTE_ADDR"]

Request.UserHostAddress

Request.UserHostName


Thank you

return client and host ip address - K Pravin Kumar Reddy replied to A S on 28-Dec-06 10:45 AM

REMOTE_ADDR
Returns the IP address of the client as a string.
example:"127.0.0.1" 

HttpRequest.UserHostAddress Property 
Gets the IP host address of the remote client.
http://msdn2.microsoft.com/en-us/library/system.web.httprequest.userhostaddress.aspx

REMOTE_ADDR - sundar k replied to A S on 28-Dec-06 11:04 AM

Request.ServerVariables["REMOTE_ADDR"] and Request.UserHostAddress serves the same purpose of retrieving Client IP address.
The former is more for compatibility with ASP.

Request.ServerVariables["REMOTE_ADDR"]
Returns the IP address of the client as a string.
example:"127.0.0.1"

Request.UserHostAddress
Gets the IP host address of the remote client.

Request.UserHostName
Gets the DNS name of the remote client.

But as per this link, its mentioned that we cannot actually get an IP address thru REMOTE_ADDR, I am not able to get this point, but still want to bring it to your notice!

http://www.velocityreviews.com/forums/t92876-requestservervariablesquotremoteaddrquot-vs-requestuserhostaddress.html

Request.ServerVariables("REMOTE_ADDR") can't give you any "real address",
since no "real address" is ever sent.

An IP address is something used at the network layer, and shouldn't really
be used by your application. If your application needs to know the identity
of the sending machine, then it should use something like X.509
certificates, which are meant to represent identity (an IP address is not).

Max replied to sundar k on 23-Aug-10 04:26 PM
I think Request.ServerVariables["REMOTE_ADDR"] is better to use.
But it wont always return an IP address!
Check out this, http://www.requestservervariables.com/remote_addr
Good luck!