Browse Source

custom dns ip & port with 'dns.conf'

dev
BreakWa11 9 years ago
parent
commit
ad625cd899
  1. 1
      apiconfig.py
  2. 29
      shadowsocks/asyncdns.py
  3. 2
      shadowsocks/obfs.py

1
apiconfig.py

@ -1,6 +1,7 @@
# Config # Config
TRANSFER_MUL = 1.0 TRANSFER_MUL = 1.0
NODE_ID = 1 NODE_ID = 1
SERVER_PUB_ADDR = '127.0.0.1'
API_INTERFACE = 'sspanelv2' #mudbjson, sspanelv2, sspanelv3, sspanelv3ssr, muapiv2(not support) API_INTERFACE = 'sspanelv2' #mudbjson, sspanelv2, sspanelv3, sspanelv3ssr, muapiv2(not support)
#mudb #mudb

29
shadowsocks/asyncdns.py

@ -283,6 +283,26 @@ class DNSResolver(object):
def _parse_resolv(self): def _parse_resolv(self):
self._servers = [] self._servers = []
try:
with open('dns.conf', 'rb') as f:
content = f.readlines()
for line in content:
line = line.strip()
if line:
parts = line.split(' ', 1)
if len(parts) >= 2:
server = parts[0]
port = int(parts[1])
else:
server = parts[0]
port = 53
if common.is_ip(server) == socket.AF_INET:
if type(server) != str:
server = server.decode('utf8')
self._servers.append((server, port))
except IOError:
pass
if not self._servers:
try: try:
with open('/etc/resolv.conf', 'rb') as f: with open('/etc/resolv.conf', 'rb') as f:
content = f.readlines() content = f.readlines()
@ -296,11 +316,12 @@ class DNSResolver(object):
if common.is_ip(server) == socket.AF_INET: if common.is_ip(server) == socket.AF_INET:
if type(server) != str: if type(server) != str:
server = server.decode('utf8') server = server.decode('utf8')
self._servers.append(server) self._servers.append((server, 53))
except IOError: except IOError:
pass pass
if not self._servers: if not self._servers:
self._servers = ['8.8.4.4', '8.8.8.8'] self._servers = [('8.8.4.4', 53), ('8.8.8.8', 53)]
logging.info('dns server: %s' % (self._servers,))
def _parse_hosts(self): def _parse_hosts(self):
etc_path = '/etc/hosts' etc_path = '/etc/hosts'
@ -400,7 +421,7 @@ class DNSResolver(object):
self._loop.add(self._sock, eventloop.POLL_IN, self) self._loop.add(self._sock, eventloop.POLL_IN, self)
else: else:
data, addr = sock.recvfrom(1024) data, addr = sock.recvfrom(1024)
if addr[0] not in self._servers: if addr not in self._servers:
logging.warn('received a packet other than our dns') logging.warn('received a packet other than our dns')
return return
self._handle_data(data) self._handle_data(data)
@ -425,7 +446,7 @@ class DNSResolver(object):
for server in self._servers: for server in self._servers:
logging.debug('resolving %s with type %d using server %s', logging.debug('resolving %s with type %d using server %s',
hostname, qtype, server) hostname, qtype, server)
self._sock.sendto(req, (server, 53)) self._sock.sendto(req, server)
def resolve(self, hostname, callback): def resolve(self, hostname, callback):
if type(hostname) != bytes: if type(hostname) != bytes:

2
shadowsocks/obfs.py

@ -45,7 +45,7 @@ class obfs(object):
if self._method_info: if self._method_info:
self.obfs = self.get_obfs(method) self.obfs = self.get_obfs(method)
else: else:
raise Exception('method %s not supported' % method) raise Exception('obfs plugin [%s] not supported' % method)
def init_data(self): def init_data(self):
return self.obfs.init_data() return self.obfs.init_data()

Loading…
Cancel
Save