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
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

45
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:

2
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()

Loading…
Cancel
Save