How can I look up a hostname given an IP address? Furthermore, how can I specify a timeout in case no such reverse DNS entry exists? Trying to keep things as fast as possible. Or is there a better way? Thank you!
>>> import socket >>> socket.gethostbyaddr("126.96.36.199") ('stackoverflow.com', ['188.8.131.52.in-addr.arpa'], ['184.108.40.206'])
For implementing the timeout on the function, this stackoverflow thread has answers on that.
What you’re trying to accomplish is called Reverse DNS lookup.
socket.gethostbyaddr("IP") # => (hostname, alias-list, IP)