PHP gethostbyname() returns 原始ip

PHP gethostbyname() returns original ip

我正在尝试使用 gethostbyname() 函数创建反向 DNS 函数,但每当我输入 IP 字符串时,例如 '104.16.34.249'(SO 的 IP),它 returns该字符串作为结果。我做错了什么?

代码(均无效):

$table['ip-host']=gethostbyname($args['args']);
$table['ip-host']=gethostbyaddr($args['args']);

expected behaviourgethostbyname() 获取域并将其转换为 IP 地址。

Returns the IPv4 address of the Internet host specified by hostname.

你通过名字(域名)得到一个主机(IP)。

尝试:

<?php
    echo gethostbyname('www.example.com');
?>

您应该获得托管 www.example.com 的服务器的 IP。

这正是 gethostbyname() 的设计目的。如果您输入主机名,它 return 是 IP 地址。如果您输入 IP 地址,它将 return IP 地址返回给您。如果您想取回主机名,请使用 gethostbyaddr()。

http://php.net/manual/en/function.gethostbyaddr.php