Python从1秒超时的IP查找主机名 [英] Python lookup hostname from IP with 1 second timeout

查看:172
本文介绍了Python从1秒超时的IP查找主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查找给定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从1秒超时的IP查找主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆