diff --git a/apiconfig.py b/apiconfig.py index fba0a75..bab5953 100644 --- a/apiconfig.py +++ b/apiconfig.py @@ -1,6 +1,7 @@ # Config TRANSFER_MUL = 1.0 NODE_ID = 1 +SERVER_PUB_ADDR = '127.0.0.1' API_INTERFACE = 'sspanelv2' #mudbjson, sspanelv2, sspanelv3, sspanelv3ssr, muapiv2(not support) #mudb diff --git a/shadowsocks/asyncdns.py b/shadowsocks/asyncdns.py index ebd5e9e..3273c36 100644 --- a/shadowsocks/asyncdns.py +++ b/shadowsocks/asyncdns.py @@ -284,23 +284,44 @@ class DNSResolver(object): def _parse_resolv(self): self._servers = [] try: - with open('/etc/resolv.conf', 'rb') as f: + with open('dns.conf', 'rb') as f: content = f.readlines() for line in content: line = line.strip() if line: - if line.startswith(b'nameserver'): - parts = line.split() - if len(parts) >= 2: - server = parts[1] - if common.is_ip(server) == socket.AF_INET: - if type(server) != str: - server = server.decode('utf8') - self._servers.append(server) + 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: - self._servers = ['8.8.4.4', '8.8.8.8'] + try: + with open('/etc/resolv.conf', 'rb') as f: + content = f.readlines() + for line in content: + line = line.strip() + if line: + if line.startswith(b'nameserver'): + parts = line.split() + if len(parts) >= 2: + server = parts[1] + if common.is_ip(server) == socket.AF_INET: + if type(server) != str: + server = server.decode('utf8') + self._servers.append((server, 53)) + except IOError: + pass + if not self._servers: + self._servers = [('8.8.4.4', 53), ('8.8.8.8', 53)] + logging.info('dns server: %s' % (self._servers,)) def _parse_hosts(self): etc_path = '/etc/hosts' @@ -400,7 +421,7 @@ class DNSResolver(object): self._loop.add(self._sock, eventloop.POLL_IN, self) else: 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') return self._handle_data(data) @@ -425,7 +446,7 @@ class DNSResolver(object): for server in self._servers: logging.debug('resolving %s with type %d using server %s', hostname, qtype, server) - self._sock.sendto(req, (server, 53)) + self._sock.sendto(req, server) def resolve(self, hostname, callback): if type(hostname) != bytes: diff --git a/shadowsocks/obfs.py b/shadowsocks/obfs.py index f34c7c0..68a92f1 100644 --- a/shadowsocks/obfs.py +++ b/shadowsocks/obfs.py @@ -45,7 +45,7 @@ class obfs(object): if self._method_info: self.obfs = self.get_obfs(method) else: - raise Exception('method %s not supported' % method) + raise Exception('obfs plugin [%s] not supported' % method) def init_data(self): return self.obfs.init_data()