mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-08-09 23:57:36 +02:00
iptables.py: completely replace ipt script.
Doing it in python instead of shell makes the code a bit less error prone. Plus we can parse the iptables output and avoid triggering iptables errors.
This commit is contained in:
27
client.py
27
client.py
@ -21,16 +21,7 @@ def iptables_setup(port, subnets):
|
||||
raise Exception('%r returned %d' % (argv, rv))
|
||||
|
||||
|
||||
def main(listenip, remotename, subnets):
|
||||
log('Starting sshuttle proxy.\n')
|
||||
listener = socket.socket()
|
||||
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
listener.bind(listenip)
|
||||
listener.listen(10)
|
||||
log('Listening on %r.\n' % (listener.getsockname(),))
|
||||
|
||||
iptables_setup(listenip[1], subnets)
|
||||
|
||||
def _main(listener, remotename, subnets):
|
||||
handlers = []
|
||||
def onaccept():
|
||||
sock,srcip = listener.accept()
|
||||
@ -61,3 +52,19 @@ def main(listenip, remotename, subnets):
|
||||
for s in handlers:
|
||||
if s.socks & ready:
|
||||
s.callback()
|
||||
|
||||
|
||||
def main(listenip, remotename, subnets):
|
||||
log('Starting sshuttle proxy.\n')
|
||||
listener = socket.socket()
|
||||
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
listener.bind(listenip)
|
||||
listener.listen(10)
|
||||
log('Listening on %r.\n' % (listener.getsockname(),))
|
||||
|
||||
iptables_setup(listenip[1], subnets)
|
||||
|
||||
try:
|
||||
return _main(listener, remotename, subnets)
|
||||
finally:
|
||||
iptables_setup(listenip[1], [])
|
||||
|
Reference in New Issue
Block a user