mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-01-05 21:48:54 +01:00
dns: extract 'nameserver' lines from /etc/resolv.conf
This commit is contained in:
parent
a2fcb08a2d
commit
4c5185dc55
12
firewall.py
12
firewall.py
@ -82,11 +82,13 @@ def do_iptables(port, dnsport, subnets):
|
||||
'--to-ports', str(port))
|
||||
|
||||
if dnsport:
|
||||
ipt_ttl('-A', chain, '-j', 'REDIRECT',
|
||||
'--dest', '192.168.42.1/32',
|
||||
'-p', 'udp',
|
||||
'--dport', '53',
|
||||
'--to-ports', str(dnsport))
|
||||
nslist = resolvconf_nameservers()
|
||||
for ip in nslist:
|
||||
ipt_ttl('-A', chain, '-j', 'REDIRECT',
|
||||
'--dest', '%s/32' % ip,
|
||||
'-p', 'udp',
|
||||
'--dport', '53',
|
||||
'--to-ports', str(dnsport))
|
||||
|
||||
|
||||
def ipfw_rule_exists(n):
|
||||
|
23
helpers.py
23
helpers.py
@ -35,3 +35,26 @@ def list_contains_any(l, sub):
|
||||
if i in l:
|
||||
return True
|
||||
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'
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user