简体   繁体   English

为什么gethostbyaddr()返回不同的结果?

[英]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/ 确实是当我在http://writecodeonline.com/php/上对其进行测试时

But when I run this code on my Windows machine I get: 但是,当我在Windows计算机上运行此代码时,我得到:

50.31.210.85 fight.com

I tested many different domains, is it because of Windows or some other configuration problem? 我测试了许多不同的域,是因为Windows还是其他一些配置问题?

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 Windows计算机上的主机文件或Windows计算机使用的DNS上的记录绑定了50.31.210.85的反向映射,将其解析为fight.com

You can very easily test the case with the following 2 commands: 您可以使用以下2个命令轻松测试这种情况:

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 第一个应该返回fight.com因为它将使用您的计算机DNS
The second should return unknown.servercentral.net since it will use Google open DNS 第二个应该返回unknown.servercentral.net因为它将使用Google开放式DNS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM