简体   繁体   English

Python:共享主机中的反向 DNS 查找

[英]Python: Reverse DNS Lookup in a shared hosting

Is there any way to do a reverse lookup using python, to check the list of websites sharing the same IP address in a shared hosting.有什么方法可以使用 python 进行反向查找,以检查共享主机中共享相同 IP 地址的网站列表。

Some web sites offer a tool for this purpose . 一些网站为此提供了一种工具。

DNSPython DNSPython

Technically, you can use DNSPython to do a reverse lookup.从技术上讲,您可以使用DNSPython进行反向查找。

Pip install it点安装它

$ pip install dnspython

Then do your reverse query:然后做你的反向查询:

>>> from dns import resolver
>>> from dns import reversename
>>> addr = reversename.from_address("74.125.227.114")
>>> resolver.query(addr, "PTR")[0]
<DNS IN PTR rdata: dfw06s16-in-f18.1e100.net.>

socket.gethostbyaddr

You can also use socket.gethostbyaddr您也可以使用socket.gethostbyaddr

>>> import socket
>>> name, alias, addresslist = socket.gethostbyaddr('192.30.252.130')
>>> name
'ip1c-lb3-prd.iad.github.com'

Note that you'll want to check for a socket.herror Exception when using gethostbyaddr .请注意,在使用gethostbyaddr时,您需要检查socket.herror异常。

Problems with doing a reverse lookup进行反向查找的问题

As for finding out what sites are hosted on a particular IP, this may not lend the best results in a shared hosting environment.至于找出哪些站点托管在特定 IP 上,这可能无法在共享托管环境中获得最佳结果。 It will likely tell you about the provider, not the site:它可能会告诉您有关提供商的信息,而不是网站:

14:38:43 ~/code/tmp$ ping mozeyondown.com
PING mozeyondown.com (173.203.99.161): 56 data bytes
64 bytes from 173.203.99.161: icmp_seq=0 ttl=56 time=40.924 ms

Let's look up that address now我们现在查一下那个地址

14:38:54 ~/code/tmp$ dig +noall +answer -x 173.203.99.161
161.99.203.173.in-addr.arpa. 86053 IN   PTR 173-203-99-161.static.cloud-ips.com.

Looking it up via Python通过 Python 查找

>>> import socket
>>> name, alias, addresslist = socket.gethostbyaddr('173.203.99.161')
>>> name
'173-203-99-161.static.cloud-ips.com'

Same goes for using DNSPython.使用 DNSPython 也是如此。

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

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