def connect(self, host, port=None, through=None): '''establish a secure shell tunnel between local and remote host Input: host -- remote hostname [user@host:path is also valid] port -- remote port number Additional Input: through -- 'tunnel-through' hostname [default = None] ''' from pathos.portpicker import portnumber if port is None: from pathos.core import randomport port = randomport(through) if through else randomport(host) pick = portnumber(self.MINPORT, self.MAXPORT) while True: localport = pick() if localport < 0: raise TunnelException, 'No available local port' #print 'Trying port %d...' % localport try: self._connect(localport, host, port, through=through) #print 'SSH tunnel %d:%s:%d' % (localport, host, port) except TunnelException, e: if e.args[0] == 'bind': self.disconnect() continue else: self.__disconnect() raise TunnelException, 'Connection failed' self.connected = True return localport
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] """ from pathos.portpicker import portnumber pick = 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.__disconnect() raise TunnelException, "Connection failed" self.connected = True return port
def _installSocket(self, host, port): """prepare a listening socket""" from pathos.portpicker import portnumber s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if port == 0: #Get a random port pick = 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
def _installSocket(self, host, port): """prepare a listening socket""" from pathos.portpicker import portnumber s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if port == 0: #Get a random port pick = 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