本文介绍了Python:共享主机中的反向 DNS 查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使用 python 进行反向查找,以检查共享主机中共享相同 IP 地址的网站列表.

一些网站为此提供了一个工具.

解决方案

DNSPython

从技术上讲,您可以使用 DNSPython 进行反向查找.

pip 安装

$ pip install dnspython

然后进行反向查询:

>>>从 dns 导入解析器>>>从 dns 导入反向名称>>>addr = reversename.from_address("74.125.227.114")>>>resolver.query(addr, "PTR")[0]<DNS IN PTR rdata: dfw06s16-in-f18.1e100.net.>

socket.gethostbyaddr

你也可以使用socket.gethostbyaddr

>>>进口插座>>>名称,别名,地址列表 = socket.gethostbyaddr('192.30.252.130')>>>名称'ip1c-lb3-prd.iad.github.com'

请注意,在使用 gethostbyaddr 时,您需要检查 socket.herror 异常.

反向查找的问题

至于找出哪些站点托管在特定 IP 上,这可能无法在共享托管环境中获得最佳结果.它可能会告诉您有关提供商的信息,而不是网站:

14:38:43 ~/code/tmp$ ping mozeyondown.comPING mozeyondown.com (173.203.99.161):56 个数据字节来自 173.203.99.161 的 64 个字节:icmp_seq=0 ttl=56 time=40.924 ms

让我们现在查找该地址

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

通过 Python 查找

>>>进口插座>>>名称,别名,地址列表 = socket.gethostbyaddr('173.203.99.161')>>>名称'173-203-99-161.static.cloud-ips.com'

同样适用于使用 DNSPython.

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.

Some web sites offer a tool for this purpose .

解决方案

DNSPython

Technically, you can use DNSPython to do a reverse lookup.

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

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

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

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

这篇关于Python:共享主机中的反向 DNS 查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 09:03