Improve resolving hostnames
This commit is contained in:
@@ -565,12 +565,12 @@ def get_ip(host):
|
|||||||
ip_address = ''
|
ip_address = ''
|
||||||
if is_valid_ip(host):
|
if is_valid_ip(host):
|
||||||
return host
|
return host
|
||||||
else:
|
elif not re.fullmatch(r'[0-9]+(?:\.[0-9]+){3}(?!\d*-[a-z0-9]{6})', host):
|
||||||
try:
|
try:
|
||||||
ip_address = socket.getaddrinfo(host, None)[0][4][0]
|
ip_address = socket.getaddrinfo(host, None)[0][4][0]
|
||||||
logger.debug(u"IP Checker :: Resolved %s to %s." % (host, ip_address))
|
logger.debug(u"IP Checker :: Resolved %s to %s." % (host, ip_address))
|
||||||
except:
|
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
|
return ip_address
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user