Browse Source

custom dns ip & port with 'dns.conf'

dev
BreakWa11 9 years ago
parent
commit
ad625cd899
  1. 1
      apiconfig.py
  2. 45
      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

45
shadowsocks/asyncdns.py

@ -284,23 +284,44 @@ class DNSResolver(object):
def _parse_resolv(self): def _parse_resolv(self):
self._servers = [] self._servers = []
try: try:
with open('/etc/resolv.conf', 'rb') as f: with open('dns.conf', 'rb') as f:
content = f.readlines() content = f.readlines()
for line in content: for line in content:
line = line.strip() line = line.strip()
if line: if line:
if line.startswith(b'nameserver'): parts = line.split(' ', 1)
parts = line.split() if len(parts) >= 2:
if len(parts) >= 2: server = parts[0]
server = parts[1] port = int(parts[1])
if common.is_ip(server) == socket.AF_INET: else:
if type(server) != str: server = parts[0]
server = server.decode('utf8') port = 53
self._servers.append(server) if common.is_ip(server) == socket.AF_INET:
if type(server) != str:
server = server.decode('utf8')
self._servers.append((server, port))
except IOError: except IOError:
pass pass
if not self._servers: 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): 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