Python 从 IP 查找主机名,超时 1 秒 [英] Python lookup hostname from IP with 1 second timeout
本文介绍了Python 从 IP 查找主机名,超时 1 秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在给定 IP 地址的情况下查找主机名?此外,如果不存在此类反向 DNS 条目,我该如何指定超时时间?试图让事情尽可能快.或者,还有更好的方法?谢谢!
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("69.59.196.211")
('stackoverflow.com', ['211.196.59.69.in-addr.arpa'], ['69.59.196.211'])
为了在函数上实现超时,这个stackoverflow线程有答案
For implementing the timeout on the function, this stackoverflow thread has answers on that.
这篇关于Python 从 IP 查找主机名,超时 1 秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文