object404
object404

Reputation: 15

How to get dns via ip address in python3.x

I was able to get the ip address corresponding to the dns through the socket library Conversely, is it possible to get a dns address via an ip address?

Upvotes: 0

Views: 147

Answers (1)

Patrick Mevzek
Patrick Mevzek

Reputation: 12515

Yes, see socket.gethostbyaddr at https://docs.python.org/3.10/library/socket.html#socket.gethostbyaddr

Note however that this is of dubious interest. It relies on the existence of PTR records in the DNS, which are absolutely not guaranteed to exist and will even seldom exist, as they are not needed for the vast majority of cases.

You can do the same and verify findings by using dig -x command.

Upvotes: 0

Related Questions