mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-01-08 06:59:32 +01:00
dns: extract 'nameserver' lines from /etc/resolv.conf
This commit is contained in:
parent
a2fcb08a2d
commit
4c5185dc55
@ -82,8 +82,10 @@ def do_iptables(port, dnsport, subnets):
|
|||||||
'--to-ports', str(port))
|
'--to-ports', str(port))
|
||||||
|
|
||||||
if dnsport:
|
if dnsport:
|
||||||
|
nslist = resolvconf_nameservers()
|
||||||
|
for ip in nslist:
|
||||||
ipt_ttl('-A', chain, '-j', 'REDIRECT',
|
ipt_ttl('-A', chain, '-j', 'REDIRECT',
|
||||||
'--dest', '192.168.42.1/32',
|
'--dest', '%s/32' % ip,
|
||||||
'-p', 'udp',
|
'-p', 'udp',
|
||||||
'--dport', '53',
|
'--dport', '53',
|
||||||
'--to-ports', str(dnsport))
|
'--to-ports', str(dnsport))
|
||||||
|
23
helpers.py
23
helpers.py
@ -35,3 +35,26 @@ def list_contains_any(l, sub):
|
|||||||
if i in l:
|
if i in l:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def resolvconf_nameservers():
|
||||||
|
l = []
|
||||||
|
for line in open('/etc/resolv.conf'):
|
||||||
|
words = line.lower().split()
|
||||||
|
if len(words) >= 2 and words[0] == 'nameserver':
|
||||||
|
l.append(words[1])
|
||||||
|
return l
|
||||||
|
|
||||||
|
|
||||||
|
def resolvconf_random_nameserver():
|
||||||
|
l = resolvconf_nameservers()
|
||||||
|
if l:
|
||||||
|
if len(l) > 1:
|
||||||
|
# don't import this unless we really need it
|
||||||
|
import random
|
||||||
|
random.shuffle(l)
|
||||||
|
return l[0]
|
||||||
|
else:
|
||||||
|
return '127.0.0.1'
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ class DnsProxy(Handler):
|
|||||||
self.mux = mux
|
self.mux = mux
|
||||||
self.chan = chan
|
self.chan = chan
|
||||||
self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
|
self.sock.setsockopt(socket.SOL_IP, socket.IP_TTL, 42)
|
||||||
self.sock.connect(('192.168.42.1', 53))
|
self.sock.connect((resolvconf_random_nameserver(), 53))
|
||||||
self.sock.send(request)
|
self.sock.send(request)
|
||||||
|
|
||||||
def callback(self):
|
def callback(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user