Improve resolving hostnames

This commit is contained in:
JonnyWong16 2019-11-02 10:38:14 -07:00
parent bb1bf87fe2
commit f5794a5bae

View file

@ -565,12 +565,12 @@ def get_ip(host):
ip_address = ''
if is_valid_ip(host):
return host
else:
elif not re.fullmatch(r'[0-9]+(?:\.[0-9]+){3}(?!\d*-[a-z0-9]{6})', host):
try:
ip_address = socket.getaddrinfo(host, None)[0][4][0]
logger.debug(u"IP Checker :: Resolved %s to %s." % (host, ip_address))
except:
logger.error(u"IP Checker :: Bad IP or hostname provided.")
logger.error(u"IP Checker :: Bad IP or hostname provided: %s." % host)
return ip_address