def lookup_ip_address(self, ip):
"""
Perform a reverse DNS lookup for ip.
Uses self.cache to speed up results when the same ip is
lookup up several times during one session.
:param ip: IP address to look up
"""
if ip is None:
return None
if ip not in self.cache:
try:
self.cache[ip] = gethostbyaddr(ip)[0]
except (herror, gaierror):
# if lookup fails, return the input address
self.cache[ip] = ip
return self.cache[ip]
评论列表
文章目录