Esempio n. 1
0
def tunnel_connection(socket,
                      addr,
                      server,
                      keyfile=None,
                      password=None,
                      paramiko=None):
    """Connect a socket to an address via an ssh tunnel.
    
    This is a wrapper for socket.connect(addr), when addr is not accessible
    from the local machine.  It simply creates an ssh tunnel using the remaining args,
    and calls socket.connect('tcp://localhost:lport') where lport is the randomly
    selected local port of the tunnel.
    
    """
    lport = select_random_ports(1)[0]
    transport, addr = addr.split('://')
    ip, rport = addr.split(':')
    rport = int(rport)
    if paramiko is None:
        paramiko = sys.platform == 'win32'
    if paramiko:
        tunnelf = paramiko_tunnel
    else:
        tunnelf = openssh_tunnel
    tunnel = tunnelf(lport,
                     rport,
                     server,
                     remoteip=ip,
                     keyfile=keyfile,
                     password=password)
    socket.connect('tcp://127.0.0.1:%i' % lport)
    return tunnel
Esempio n. 2
0
 def init_ssh(self):
     """set up ssh tunnels, if needed."""
     if not self.sshserver and not self.sshkey:
         return
     
     if self.sshkey and not self.sshserver:
         self.sshserver = self.ip
         self.ip=LOCALHOST
     
     lports = select_random_ports(4)
     rports = self.shell_port, self.iopub_port, self.stdin_port, self.hb_port
     self.shell_port, self.iopub_port, self.stdin_port, self.hb_port = lports
     
     remote_ip = self.ip
     self.ip = LOCALHOST
     self.log.info("Forwarding connections to %s via %s"%(remote_ip, self.sshserver))
     
     if tunnel.try_passwordless_ssh(self.sshserver, self.sshkey):
         password=False
     else:
         password = getpass("SSH Password for %s: "%self.sshserver)
     
     for lp,rp in zip(lports, rports):
         tunnel.ssh_tunnel(lp, rp, self.sshserver, remote_ip, self.sshkey, password)
     
     self.log.critical("To connect another client to this tunnel, use:")
     self.log.critical(
         "--existing --shell={0} --iopub={1} --stdin={2} --hb={3}".format(
             self.shell_port, self.iopub_port, self.stdin_port,
             self.hb_port))
Esempio n. 3
0
def tunnel_connection(socket, addr, server, keyfile=None, password=None, paramiko=None):
    """Connect a socket to an address via an ssh tunnel.
    
    This is a wrapper for socket.connect(addr), when addr is not accessible
    from the local machine.  It simply creates an ssh tunnel using the remaining args,
    and calls socket.connect('tcp://localhost:lport') where lport is the randomly
    selected local port of the tunnel.
    
    """
    lport = select_random_ports(1)[0]
    transport, addr = addr.split('://')
    ip,rport = addr.split(':')
    rport = int(rport)
    if paramiko is None:
        paramiko = sys.platform == 'win32'
    if paramiko:
        tunnelf = paramiko_tunnel
    else:
        tunnelf = openssh_tunnel
    tunnel = tunnelf(lport, rport, server, remoteip=ip, keyfile=keyfile, password=password)
    socket.connect('tcp://127.0.0.1:%i'%lport)
    return tunnel
Esempio n. 4
0
 def init_ssh(self):
     """set up ssh tunnels, if needed."""
     if not self.sshserver and not self.sshkey:
         return
     
     if self.sshkey and not self.sshserver:
         self.sshserver = self.ip
         self.ip=LOCALHOST
     
     lports = select_random_ports(4)
     rports = self.shell_port, self.iopub_port, self.stdin_port, self.hb_port
     self.shell_port, self.iopub_port, self.stdin_port, self.hb_port = lports
     
     remote_ip = self.ip
     self.ip = LOCALHOST
     self.log.info("Forwarding connections to %s via %s"%(remote_ip, self.sshserver))
     
     if tunnel.try_passwordless_ssh(self.sshserver, self.sshkey):
         password=False
     else:
         password = getpass("SSH Password for %s: "%self.sshserver)
     
     for lp,rp in zip(lports, rports):
         tunnel.ssh_tunnel(lp, rp, self.sshserver, remote_ip, self.sshkey, password)
Esempio n. 5
0
File: hub.py Progetto: ddale/ipython
 def _mon_port_default(self):
     return util.select_random_ports(1)[0]
Esempio n. 6
0
File: hub.py Progetto: ddale/ipython
 def _hb_default(self):
     return util.select_random_ports(2)
Esempio n. 7
0
 def _iopub_default(self):
     return tuple(util.select_random_ports(2))
Esempio n. 8
0
 def _mux_default(self):
     return select_random_ports(2)
Esempio n. 9
0
 def _notifier_port_default(self):
     return select_random_ports(1)[0]
Esempio n. 10
0
 def _control_default(self):
     return select_random_ports(2)
Esempio n. 11
0
 def _iopub_default(self):
     return util.select_random_ports(2)
Esempio n. 12
0
 def _control_default(self):
     return util.select_random_ports(2)
Esempio n. 13
0
 def _task_default(self):
     return util.select_random_ports(2)
Esempio n. 14
0
 def _regport_default(self):
     return select_random_ports(1)[0]
Esempio n. 15
0
 def _mux_default(self):
     return tuple(util.select_random_ports(2))
Esempio n. 16
0
 def _mux_default(self):
     return select_random_ports(2)
Esempio n. 17
0
 def _task_default(self):
     return select_random_ports(2)
Esempio n. 18
0
 def _mon_port_default(self):
     return util.select_random_ports(1)[0]
Esempio n. 19
0
 def _iopub_default(self):
     return select_random_ports(2)
Esempio n. 20
0
 def _notifier_port_default(self):
     return util.select_random_ports(1)[0]
Esempio n. 21
0
 def _regport_default(self):
     return select_random_ports(1)[0]
Esempio n. 22
0
 def _control_default(self):
     return tuple(util.select_random_ports(2))