getting host name

B

Brian Henry

is there a way to get the host name of someone? like mine is
68-23-123-123-pitt-pa.adelphia.net?

Request.UserHostName doesn't seem to return the host name like it states in
the documentation, only gives me back an IP address.. which is what I
assumed Request.UserHostAddress would do... they both return the same values
all the time
 
B

Brian Henry

I just tried that and it seems to only be returning the host name of the
server, shouldn't this be the host name of the client? which is what I want
not the server the application it is running on... REMOTE_HOST returns the
client IP, but I want the client host name.. thanks!
 
R

recoil

the REMOTE_HOST returning the IP instead of the actual hostname is a
server configuration. Most servers disable reverse lookup because it
does slow things down unnecessarily.

You will usually have to do the reverse lookup yourself manually and
you can use the following code as a basis

System.Net.IPHostEntry TmpEntry =
System.Net.Dns.GetHostByAddress(Request.ServerVariables["REMOTE_ADDR"]);
Response.Write(TmpEntry.HostName + "<br />");
 
J

Juan T. Llibre

re:
shouldn't this be the host name of the client?

No. It's the host name of the http server.

re:
I want the client host name

You can't have that, since the client is not hosting anything.

You could, if you need that info, do a reverse DNS query.
*That* would give you the client's name, if any exists.
 
J

Juan T. Llibre

Hmm...

I thought that would get you the machine's name,
but not the DNS name.
 
Joined
Mar 9, 2012
Messages
1
Reaction score
0
Use this instead:

System.Net.IPHostEntry ip
= System.Net.Dns.GetHostByAddress(Request.UserHostAddress);

string hostname = ip.HostName;
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top