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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了实现函数的超时,这个 stackoverflow 线程对此有答案。
For implementing the timeout on the function, this stackoverflow thread has answers on that.
您想要完成的任务称为反向 DNS 查找。
http://docs.python.org/library/socket.html ?highlight=gethostbyaddr#socket.gethostbyaddr
但是,对于超时部分,我读到了有关人们遇到此问题的信息。我会查看 PyDNS 或 此解决方案用于更高级的治疗。
What you're trying to accomplish is called Reverse DNS lookup.
http://docs.python.org/library/socket.html?highlight=gethostbyaddr#socket.gethostbyaddr
However, for the timeout part I have read about people running into problems with this. I would check out PyDNS or this solution for more advanced treatment.