def hostname(ip):
"""
Performs a DNS reverse lookup for an IP address and caches the result in
a global variable, which is really, really stupid.
:param ip: And IP address string.
:returns: A hostname string or a False value if the lookup failed.
"""
addr = unicode(ip)
if addr in _cached_hostname:
return _cached_hostname[addr]
try:
dns = gethostbyaddr(addr)
except herror:
return False
_cached_hostname[addr] = dns[0]
return dns[0]
评论列表
文章目录