Why doesn't gethostbyaddr() work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wwuster
Forum Newbie
Posts: 6
Joined: Sat Nov 08, 2008 6:01 am

Why doesn't gethostbyaddr() work?

Post 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
wwuster
Forum Newbie
Posts: 6
Joined: Sat Nov 08, 2008 6:01 am

Re: Why doesn't gethostbyaddr() work?

Post 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
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Why doesn't gethostbyaddr() work?

Post 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
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

Re: Why doesn't gethostbyaddr() work?

Post by mrvijayakumar »

Hi dear,
Read this article for more, http://in2.php.net/gethostbyaddr. U can also find some related functions tooo.
Post Reply