Good question. I actually was stuck with something like this in the past.
Here's the solution. Check out the following piece of code:
>>> import socket
>>> socket.gethostbyaddr("69.59.196.211")
('stackoverflow.com', ['211.196.59.69.in-addr.arpa'], ['69.59.196.211'])
You can also implement the timeout on the particular function as you desire.
Hope this helped!