Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sshuttle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
sshuttle
Commits
4c5185dc
Commit
4c5185dc
authored
Jan 26, 2011
by
Avery Pennarun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dns: extract 'nameserver' lines from /etc/resolv.conf
parent
a2fcb08a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
6 deletions
+31
-6
firewall.py
firewall.py
+7
-5
helpers.py
helpers.py
+23
-0
server.py
server.py
+1
-1
No files found.
firewall.py
View file @
4c5185dc
...
...
@@ -82,8 +82,10 @@ def do_iptables(port, dnsport, subnets):
'--to-ports'
,
str
(
port
))
if
dnsport
:
nslist
=
resolvconf_nameservers
()
for
ip
in
nslist
:
ipt_ttl
(
'-A'
,
chain
,
'-j'
,
'REDIRECT'
,
'--dest'
,
'192.168.42.1/32'
,
'--dest'
,
'
%
s/32'
%
ip
,
'-p'
,
'udp'
,
'--dport'
,
'53'
,
'--to-ports'
,
str
(
dnsport
))
...
...
helpers.py
View file @
4c5185dc
...
...
@@ -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'
server.py
View file @
4c5185dc
...
...
@@ -114,7 +114,7 @@ class DnsProxy(Handler):
self
.
mux
=
mux
self
.
chan
=
chan
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
)
def
callback
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment