|
@ -476,8 +476,8 @@ class DNSResolver(object): |
|
|
logging.debug('hit cache: %s', hostname) |
|
|
logging.debug('hit cache: %s', hostname) |
|
|
ip = self._cache[hostname] |
|
|
ip = self._cache[hostname] |
|
|
callback((hostname, ip), None) |
|
|
callback((hostname, ip), None) |
|
|
elif hostname in self._black_hostname_list: |
|
|
elif any(hostname.endswith(t) for t in self._black_hostname_list): |
|
|
callback(None, Exception('hostname <%s> in the black hostname list' % hostname)) |
|
|
callback(None, Exception('hostname <%s> is block by the black hostname list' % hostname)) |
|
|
return |
|
|
return |
|
|
else: |
|
|
else: |
|
|
if not is_valid_hostname(hostname): |
|
|
if not is_valid_hostname(hostname): |
|
@ -521,7 +521,8 @@ class DNSResolver(object): |
|
|
|
|
|
|
|
|
def test(): |
|
|
def test(): |
|
|
black_hostname_list = [ |
|
|
black_hostname_list = [ |
|
|
'baidu.com' |
|
|
'baidu.com', |
|
|
|
|
|
'yahoo.com', |
|
|
] |
|
|
] |
|
|
dns_resolver = DNSResolver(black_hostname_list=black_hostname_list) |
|
|
dns_resolver = DNSResolver(black_hostname_list=black_hostname_list) |
|
|
loop = eventloop.EventLoop() |
|
|
loop = eventloop.EventLoop() |
|
@ -538,7 +539,7 @@ def test(): |
|
|
# TODO: what can we assert? |
|
|
# TODO: what can we assert? |
|
|
print(result, error) |
|
|
print(result, error) |
|
|
counter += 1 |
|
|
counter += 1 |
|
|
if counter == 9: |
|
|
if counter == 12: |
|
|
dns_resolver.close() |
|
|
dns_resolver.close() |
|
|
loop.stop() |
|
|
loop.stop() |
|
|
|
|
|
|
|
@ -550,6 +551,8 @@ def test(): |
|
|
dns_resolver.resolve(b'google.com', make_callback()) |
|
|
dns_resolver.resolve(b'google.com', make_callback()) |
|
|
dns_resolver.resolve('google.com', make_callback()) |
|
|
dns_resolver.resolve('google.com', make_callback()) |
|
|
dns_resolver.resolve('baidu.com', make_callback()) |
|
|
dns_resolver.resolve('baidu.com', make_callback()) |
|
|
|
|
|
dns_resolver.resolve('map.baidu.com', make_callback()) |
|
|
|
|
|
dns_resolver.resolve('yahoo.com', make_callback()) |
|
|
dns_resolver.resolve('example.com', make_callback()) |
|
|
dns_resolver.resolve('example.com', make_callback()) |
|
|
dns_resolver.resolve('ipv6.google.com', make_callback()) |
|
|
dns_resolver.resolve('ipv6.google.com', make_callback()) |
|
|
dns_resolver.resolve('www.facebook.com', make_callback()) |
|
|
dns_resolver.resolve('www.facebook.com', make_callback()) |
|
|