Show More
@@ -110,6 +110,22 b' def tunnel_connection(socket, addr, server, keyfile=None, password=None, paramik' | |||||
110 | selected local port of the tunnel. |
|
110 | selected local port of the tunnel. | |
111 |
|
111 | |||
112 | """ |
|
112 | """ | |
|
113 | new_url, tunnel = open_tunnel(addr, server, keyfile=keyfile, password=password, paramiko=paramiko) | |||
|
114 | socket.connect(new_url) | |||
|
115 | return tunnel | |||
|
116 | ||||
|
117 | ||||
|
118 | def open_tunnel(addr, server, keyfile=None, password=None, paramiko=None): | |||
|
119 | """Open a tunneled connection from a 0MQ url. | |||
|
120 | ||||
|
121 | For use inside tunnel_connection. | |||
|
122 | ||||
|
123 | Returns | |||
|
124 | ------- | |||
|
125 | ||||
|
126 | (url, tunnel): The 0MQ url that has been forwarded, and the tunnel object | |||
|
127 | """ | |||
|
128 | ||||
113 | lport = select_random_ports(1)[0] |
|
129 | lport = select_random_ports(1)[0] | |
114 | transport, addr = addr.split('://') |
|
130 | transport, addr = addr.split('://') | |
115 | ip,rport = addr.split(':') |
|
131 | ip,rport = addr.split(':') | |
@@ -121,8 +137,7 b' def tunnel_connection(socket, addr, server, keyfile=None, password=None, paramik' | |||||
121 | else: |
|
137 | else: | |
122 | tunnelf = openssh_tunnel |
|
138 | tunnelf = openssh_tunnel | |
123 | tunnel = tunnelf(lport, rport, server, remoteip=ip, keyfile=keyfile, password=password) |
|
139 | tunnel = tunnelf(lport, rport, server, remoteip=ip, keyfile=keyfile, password=password) | |
124 |
|
|
140 | return 'tcp://127.0.0.1:%i'%lport, tunnel | |
125 | return tunnel |
|
|||
126 |
|
141 | |||
127 | def openssh_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=15): |
|
142 | def openssh_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=15): | |
128 | """Create an ssh tunnel using command-line ssh that connects port lport |
|
143 | """Create an ssh tunnel using command-line ssh that connects port lport |
General Comments 0
You need to be logged in to leave comments.
Login now