Skip to content

Commit

Permalink
fix: load default nameservers from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
gera2ld committed Dec 2, 2019
1 parent 36d1eff commit 16cf636
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 19 additions & 2 deletions async_dns/core/config/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,32 @@
'''

import os
import json
from .. import logger, types, Record

__all__ = [
'core_config',
'get_name_cache',
'get_root_servers',
]

CACHE_FILE = os.path.expanduser('~/.async_dns/named.cache.txt')
CONFIG_DIR = os.path.expanduser('~/.config/async_dns')
os.makedirs(CONFIG_DIR, exist_ok=True)
CACHE_FILE = os.path.join(CONFIG_DIR, 'named.cache.txt')

try:
user_config = json.load(open(os.path.join(CONFIG_DIR, 'config.json')))
except:
user_config = None
core_config = {
'default_nameservers': [
'8.8.8.8',
'8.8.4.4',
],
}
if user_config is not None:
core_config.update(user_config)
del user_config

def get_nameservers():
return []
Expand All @@ -35,7 +53,6 @@ def get_root_servers(filename=CACHE_FILE):
Load root servers from cache.
'''
if not os.path.isfile(filename):
os.makedirs(os.path.dirname(filename), exist_ok=True)
get_name_cache(filename=filename)
# in case failed fetching named.cache
if not os.path.isfile(filename):
Expand Down
5 changes: 1 addition & 4 deletions async_dns/resolver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ class ProxyResolver(Resolver):
Resolve hostnames from remote proxy servers instead of root servers.
'''
name = 'AsyncDNSProxyResolver'
default_nameservers = [
'223.5.5.5',
'223.6.6.6',
]
default_nameservers = core_config['default_nameservers']
recursive = 0

def __init__(self, *k, proxies=None, **kw):
Expand Down

0 comments on commit 16cf636

Please sign in to comment.