Forum Moderators: coopster

Message Too Old, No Replies

Does every host have a hostname.?

         

rollinj

8:39 am on Dec 17, 2009 (gmt 0)

10+ Year Member



Would it be reliable to determine whether or not an ip address was valid based on it's returned hostname using the php function:

gethostbyaddr("123.123.123.123");

Back to my original question, does every host have a hostname? And can it always be found?

ALKateb

5:03 pm on Dec 20, 2009 (gmt 0)

10+ Year Member



i would not use this inside any of my scripts cos this might take long time to return the host name if not cashed in the dns table already (read the php manual)

but what are you trying to do exactly? if a user was visiting your website and you used this function to retrive his host name it's likely that all you get is the ISP host name so what good might this do to you!

IanKelley

8:46 pm on Dec 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



No, not every IP address will resolve to a hostname, the vast majority will, however.

As ALKateb mentioned the gethostbyaddr function will lag if a hostname is not available so it's not the best choice. On a *nix system I've found that a system call to `host` is the way to go, on Windows you would call `nslookup`