Ejemplo n.º 1
0
    def connect(self, remotehost, remoteport, through=None):
        '''establish a secure shell tunnel between local and remote host

Input:
    host       -- remote hostname  [user@host:path is also valid]
    tunnelport -- remote port number

Additional Input:
    through    -- 'tunnel-through' hostname  [default = None]
        '''
        import util

        pick = util.portnumber(self.MINPORT, self.MAXPORT)
        while True:
            port = pick()
            if port < 0:
                raise TunnelException, 'No available local port'
            #print 'Trying port %d...' % port
            
            try:
                self._connect(port, remotehost, remoteport, through=through)
                #print 'SSH tunnel %d:%s:%d' % (port, remotehost, remoteport)
            except TunnelException, e:
                if e.args[0] == 'bind':
                    self.disconnect()
                    continue
                else:
                    self._pid = 0
                    self._tunnel = None #XXX: MMM
                    self.connected = False
                    raise TunnelException, 'Connection failed'
                
            self.connected = True
            return port
Ejemplo n.º 2
0
    def connect(self, remotehost, remoteport, through=None):
        """establish a secure shell tunnel between local and remote host

Input:
    host       -- remote hostname  [user@host:path is also valid]
    tunnelport -- remote port number

Additional Input:
    through    -- 'tunnel-through' hostname  [default = None]
        """
        import util

        pick = util.portnumber(self.MINPORT, self.MAXPORT)
        while True:
            port = pick()
            if port < 0:
                raise TunnelException, "No available local port"
            # print 'Trying port %d...' % port

            try:
                self._connect(port, remotehost, remoteport, through=through)
                # print 'SSH tunnel %d:%s:%d' % (port, remotehost, remoteport)
            except TunnelException, e:
                if e.args[0] == "bind":
                    self.disconnect()
                    continue
                else:
                    self._pid = 0
                    self._tunnel = None  # XXX: MMM
                    self.connected = False
                    raise TunnelException, "Connection failed"

            self.connected = True
            return port
Ejemplo n.º 3
0
    def _installSocket(self, host, port):
        """prepare a listening socket"""

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if port == 0:  #Get a random port
            pick = util.portnumber(min=port, max=64 * 1024)
            while True:
                try:
                    port = pick()
                    s.bind((host, port))
                    break
                except socket.error:
                    continue
        else:  #Designated port
            s.bind((host, port))

        s.listen(10)
        self._socket = s
        self.host = host
        self.port = port
        return
Ejemplo n.º 4
0
 def _installSocket(self, host, port):
     """prepare a listening socket"""
     
     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     if port == 0: #Get a random port
         pick = util.portnumber(min=port, max=64*1024)
         while True:
             try:
                 port = pick()
                 s.bind((host, port))
                 break
             except socket.error:
                 continue
     else: #Designated port
         s.bind((host, port))
         
     s.listen(10)
     self._socket = s
     self.host = host
     self.port = port
     return