def resolve_dns(self, shost):
"""Perform DNS lookups once per file, and cache the results. tested."""
rdns = r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
if (re.match(rdns, shost) == None):
if shost in self.dnscache:
logging.debug("Host %s in DNSCACHE, returned %s", shost, self.dnscache[shost])
shost = self.dnscache[shost]
else:
logging.debug("Host %s not in DNSCACHE", shost)
#try socket lookupt
try:
resolved_ip = socket.gethostbyname(shost)
self.dnscache[shost] = resolved_ip
logging.debug("Resolved %s to %s", shost, resolved_ip)
shost = resolved_ip
except socket.gaierror:
compiler_bailout("Cannot resolve %s" % shost)
return shost
评论列表
文章目录