How to perform a reverse DNS lookup in Python?
Asked Answered
B

1

5

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 .

Binkley answered 8/11, 2013 at 19:59 Comment(2)
This is not possible with reverse DNS. You need a database that matches hostnames to IP addresses and then search by IP address. Reverse DNS searches in the PTR records. Most domains only have one, and it's not necessarily the hosted domain. Per example, one of google.com A record points to 74.125.228.97, but the reverse DNS entry for that IP is iad23s08-in-f1.1e100.net.Festatus
I think I should use python with an another API to do this .Binkley
E
13

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.

Erotogenic answered 8/11, 2013 at 20:27 Comment(1)
I think asking for a tool to get a list of all domains hosted in 1 shared hosting IP: For exp something like bing: bing.com/search?q=IP:87.98.235.184 And/Or other paid services like : 1. yougetsignal tools web-sites-on-web-server 2. hackertarget reverse-ip-lookupVicinity

© 2022 - 2024 — McMap. All rights reserved.