我如何通过 PHP 知道 IP 的域名?
我如何通过 PHP 知道 IP 的域名?
我已经使用了这段代码
<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
echo $hostname;
?>
,但它不能正常工作。例如:
gethostbyaddr(62.75.138.253);
域名是earthwar.de,但正确答案是german-proxy.de
请帮忙。
How I can know the Domain for an IP by PHP?
I have used this code
<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
echo $hostname;
?>
But it doesn't work correctly. For example:
gethostbyaddr(62.75.138.253);
domain name is earthwar.de but the correctly answer is german-proxy.de
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
单个 IP 地址可以托管无限数量的域。
gethostbyaddr
返回的域将给出该 IP 的 PTR DNS 记录中的域名。反向 DNS 记录 (PTR) 将 IP 地址映射到一个或多个域名。Domaintools.com 就是这样一家提供 IP 地址域名情报的公司。您可以为他们获取的此类信息付费。如果域名不在 PTR 记录中,则了解 IP 地址上有哪些域的唯一方法是尝试将域名解析为其 IP 地址并保留记录。 AFK没有其他办法。
请参阅反向 DNS 查找 和 域名工具反向IP查找
域名工具反向IP查找的数据都是基于其挖掘、收集和研究。
A single IP address can host a potentially unlimited number of domains. Domains returned by
gethostbyaddr
will give the domain name(s) from the PTR DNS records for that IP. A reverse DNS record (PTR) maps IP addresses to one or more domain names.One such company that provides intelligence as far as domains on IP addresses is domaintools.com. You can pay for such information that they have harvested. If the domain name is not in the PTR record, then the only way you can know what domains are on an IP address is by attempting to resolve domain names to their IP addresses and keeping records. AFIK there is no other way.
See Reverse DNS Lookup and Domain tools reverse IP lookup
The data from the reverse IP lookup on domain tools is all based on their mining, collection and research.
可以有许多名称->IP 映射,但只有一个 IP->名称映射。当您进行主机->IP->主机查找时,最终得到完全不同的主机名并不罕见。您无法确定用户指定的主机名,除非他们使用的协议将该主机名与请求一起传输,例如 http 1.1。大多数协议纯粹基于 IP 地址工作,不需要/关心主机名。
There can be MANY name->IP mappings, but only ONE IP->name mapping. It is not unusual to end up with a completely different hostname when you do host->ip->host lookups. You cannot determine what hostname a user specified unless the protocol they're using transmits that hostname along with the request, e.g. http 1.1. Most protocols work purely off IP address and do not need/care about hostnames.
你的PHP是正确的,earthwar.de是正确的答案
这当然并不意味着其他名称(如german-proxy.de)不指向相同的地址,但没有办法找到所有这些名称。
更新:
所以这是一个很好的例子。事实是:对此你无能为力,伙计!
Your PHP is correct, earthwar.de is the correct answer
This ofcourse doesn't mean, that other names (like german-proxy.de) do not point to the same address, but there is no way to find all of them.
Update:
so this is a good example. Fact is: There aint noth'n ya can do 'bout it, dude!
您不能信任 gethostbyaddr 返回的名称。具有特定 IP 地址权限的 DNS 服务器可以返回任何主机名。
通常,管理员将 DNS 服务器设置为使用正确的主机名进行回复,但恶意用户可能会将其 DNS 服务器配置为使用错误的主机名进行回复。当您对从 gethostbyaddr 返回的主机名调用 gethostbyname 并确保该名称解析为原始 IP 地址时,您可以避免陷入该陷阱。
但还有更多...有时一个主机名可以映射到多个 IP 地址。
返回
总而言之,您需要了解 DNS 挖掘和反向 DNS 查找。这是一条漫长的路,但当我说这是一条有趣的路时,你可以相信我。
You can't trust the name returned by gethostbyaddr. A DNS server with authority for a particular IP address can return any hostname at all.
Usually, administrators set up DNS servers to reply with a correct hostname, but a malicious user may configure his/her DNS server to reply with incorrect hostnames. You can avoid falling into that trap when you call gethostbyname on the hostname returned from gethostbyaddr and make sure the name resolves to the original IP address.
But there's more... sometimes a single hostname can map to multiple IP addresses.
returns
All in all, you will need to learn about DNS digging and reverse-DNS lookups. That's a long road to walk, but you can trust me when I say it is an interesting one.