Request.ServerVariables("REMOTE_ADDR") vs. Request.UserHostAddress

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to get the visitor's ip address. Which one is the appropriate
one to use:
Request.ServerVariables("REMOTE_ADDR") or Request.UserHostAddress?

Thanks in advance.
 
hn said:
I would like to get the visitor's ip address. Which one is the appropriate
one to use:
Request.ServerVariables("REMOTE_ADDR") or Request.UserHostAddress?

I'd use Request.UserHostAddress, as the former is more for compatibility
with ASP.

Of course, you realize you're as likely to get the address of a NAT box or
proxy server as you are to get the real IP address of your visitor?

John Saunders
 
Hi John,

I remember I read somewhere that Request.ServerVariables("REMOTE_ADDR")
would give you the real address, but I'm not so sure. Anyway,
Request.UserHostAddress is good enough for me. Thanks for the quick reply,
John.
 
hn said:
Hi John,

I remember I read somewhere that Request.ServerVariables("REMOTE_ADDR")
would give you the real address, but I'm not so sure. Anyway,
Request.UserHostAddress is good enough for me. Thanks for the quick reply,

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).

John Saunders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top