我如何通过 PHP 知道 IP 的域名?

发布于 2024-12-24 02:07:49 字数 295 浏览 4 评论 0原文

我如何通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

舞袖。长 2024-12-31 02:07:49

单个 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.

带刺的爱情 2024-12-31 02:07:49

可以有许多名称->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.

你曾走过我的故事 2024-12-31 02:07:49

你的PHP是正确的,earthwar.de是正确的答案

eugen@lucidhome:~$ nslookup
> set q=ptr
> 62.75.138.253
Server:     192.168.232.1
Address:    192.168.232.1#53

Non-authoritative answer:
253.138.75.62.in-addr.arpa  name = earthwar.de.

Authoritative answers can be found from:
> 

这当然并不意味着其他名称(如german-proxy.de)不指向相同的地址,但没有办法找到所有这些名称。

更新:

eugen@lucidhome:~$ nslookup 
> set q=a
> german-proxy.de.     
Server:     192.168.232.1
Address:    192.168.232.1#53

Non-authoritative answer:
Name:   german-proxy.de
Address: 62.75.138.253
> earthwar.de.
Server:     192.168.232.1
Address:    192.168.232.1#53

Non-authoritative answer:
Name:   earthwar.de
Address: 91.143.85.129
> 

所以这是一个很好的例子。事实是:对此你无能为力,伙计!

Your PHP is correct, earthwar.de is the correct answer

eugen@lucidhome:~$ nslookup
> set q=ptr
> 62.75.138.253
Server:     192.168.232.1
Address:    192.168.232.1#53

Non-authoritative answer:
253.138.75.62.in-addr.arpa  name = earthwar.de.

Authoritative answers can be found from:
> 

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:

eugen@lucidhome:~$ nslookup 
> set q=a
> german-proxy.de.     
Server:     192.168.232.1
Address:    192.168.232.1#53

Non-authoritative answer:
Name:   german-proxy.de
Address: 62.75.138.253
> earthwar.de.
Server:     192.168.232.1
Address:    192.168.232.1#53

Non-authoritative answer:
Name:   earthwar.de
Address: 91.143.85.129
> 

so this is a good example. Fact is: There aint noth'n ya can do 'bout it, dude!

千年*琉璃梦 2024-12-31 02:07:49

您不能信任 gethostbyaddr 返回的名称。具有特定 IP 地址权限的 DNS 服务器可以返回任何主机名。

通常,管理员将 DNS 服务器设置为使用正确的主机名进行回复,但恶意用户可能会将其 DNS 服务器配置为使用错误的主机名进行回复。当您对从 gethostbyaddr 返回的主机名调用 gethostbyname 并确保该名称解析为原始 IP 地址时,您可以避免陷入该陷阱。

但还有更多...有时一个主机名可以映射到多个 IP 地址。

var_dump(gethostbynamel('google.com')); 

返回

array(6) {
   [0]=>
        string(14) "173.194.69.104"
   [1]=>
        string(14) "173.194.69.147"
   [2]=>
        string(14) "173.194.69.105"
   [3]=>
        string(14) "173.194.69.106"
   [4]=>
        string(14) "173.194.69.103"
   [5]=>
        string(13) "173.194.69.99"
}

总而言之,您需要了解 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.

var_dump(gethostbynamel('google.com')); 

returns

array(6) {
   [0]=>
        string(14) "173.194.69.104"
   [1]=>
        string(14) "173.194.69.147"
   [2]=>
        string(14) "173.194.69.105"
   [3]=>
        string(14) "173.194.69.106"
   [4]=>
        string(14) "173.194.69.103"
   [5]=>
        string(13) "173.194.69.99"
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文