Page 1 of 1

Why doesn't gethostbyaddr() work?

Posted: Thu Aug 20, 2009 2:04 pm
by wwuster
I have a script that analyzes my apache log files. I use gethsotbyaddr() to find the alpha version of ip addresses. It works about 50% of the time. Otherwise it returns the numeric ip address. If I run whois on the same ip address I
usually get an answer. One example that I just saw that does not work is baidu. Is there a way to get gethostbyaddr() to work better? I was even thinking of abandoning gethostbyaddr() and spawning whois instead.

thanks,
William

Re: Why doesn't gethostbyaddr() work?

Posted: Sat Aug 22, 2009 6:01 am
by wwuster
I've narrowed the question down.

Does this work on your system:

$name = gethostbyaddr("74.125.75.1");

When I run this it returns "74.125.75.1".
Whois shows that it is Google. Yet gethostbyaddr() works for thousands of other ip addresses. There are a few like this one that just don't work.

Any ideas?

William

Re: Why doesn't gethostbyaddr() work?

Posted: Sat Aug 22, 2009 2:21 pm
by Darhazer
I guess whois returns to whom the IP is registered
and gethostbyaddr use Reverse DNS to return the host name
And the fact that IP is registered by Google does not mean that it have a hostname

Re: Why doesn't gethostbyaddr() work?

Posted: Sat Aug 22, 2009 2:23 pm
by mrvijayakumar
Hi dear,
Read this article for more, http://in2.php.net/gethostbyaddr. U can also find some related functions tooo.