|
|
@ -233,18 +233,6 @@ def parse_response(data): |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def is_ip(address): |
|
|
|
for family in (socket.AF_INET, socket.AF_INET6): |
|
|
|
try: |
|
|
|
if type(address) != str: |
|
|
|
address = address.decode('utf8') |
|
|
|
socket.inet_pton(family, address) |
|
|
|
return family |
|
|
|
except (TypeError, ValueError, OSError, IOError): |
|
|
|
pass |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def is_valid_hostname(hostname): |
|
|
|
if len(hostname) > 255: |
|
|
|
return False |
|
|
@ -296,7 +284,7 @@ class DNSResolver(object): |
|
|
|
parts = line.split() |
|
|
|
if len(parts) >= 2: |
|
|
|
server = parts[1] |
|
|
|
if is_ip(server) == socket.AF_INET: |
|
|
|
if common.is_ip(server) == socket.AF_INET: |
|
|
|
if type(server) != str: |
|
|
|
server = server.decode('utf8') |
|
|
|
self._servers.append(server) |
|
|
@ -316,7 +304,7 @@ class DNSResolver(object): |
|
|
|
parts = line.split() |
|
|
|
if len(parts) >= 2: |
|
|
|
ip = parts[0] |
|
|
|
if is_ip(ip): |
|
|
|
if common.is_ip(ip): |
|
|
|
for i in range(1, len(parts)): |
|
|
|
hostname = parts[i] |
|
|
|
if hostname: |
|
|
@ -423,7 +411,7 @@ class DNSResolver(object): |
|
|
|
hostname = hostname.encode('utf8') |
|
|
|
if not hostname: |
|
|
|
callback(None, Exception('empty hostname')) |
|
|
|
elif is_ip(hostname): |
|
|
|
elif common.is_ip(hostname): |
|
|
|
callback((hostname, hostname), None) |
|
|
|
elif hostname in self._hosts: |
|
|
|
logging.debug('hit hosts: %s', hostname) |
|
|
|