Sunny
Sunny

Reputation: 2332

Why gethostbyaddr() returning different results?

$_POST['url'] = 'fight.com';
$host = gethostbyname($_POST['url']);  //get IP
echo $host . " ";

$ip = gethostbyaddr($host); //get hostname
echo $ip;

The expected correct result is:

50.31.210.85 unknown.servercentral.net

And indeed it is when I test it on http://writecodeonline.com/php/

But when I run this code on my Windows machine I get:

50.31.210.85 fight.com

I tested many different domains, is it because of Windows or some other configuration problem?

Upvotes: 0

Views: 295

Answers (1)

Antoan Milkov
Antoan Milkov

Reputation: 2228

The host file on your Windows machine or the DNS that your Windows machine is using has record that binds the reverse mapping of 50.31.210.85 to be resolved as fight.com

You can very easily test the case with the following 2 commands:

nslookup 50.31.210.85
nslookup 50.31.210.85 8.8.8.8

The first should return fight.com since it will use your machine DNS
The second should return unknown.servercentral.net since it will use Google open DNS

Upvotes: 2

Related Questions