$_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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.