当前位置: 首页>>代码示例>>Python>>正文


Python sshtunnel.SSHTunnelForwarder类代码示例

本文整理汇总了Python中sshtunnel.SSHTunnelForwarder的典型用法代码示例。如果您正苦于以下问题:Python SSHTunnelForwarder类的具体用法?Python SSHTunnelForwarder怎么用?Python SSHTunnelForwarder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SSHTunnelForwarder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SSHTunnel

class SSHTunnel(object):
    class TunnelException(Exception):
        pass

    def __init__(self, host, username, key_file, remote_port, host_port=nat_ssh_port_forwarding):
        """
        Returns tuple consisting of local port and sshtunnel SSHTunnelForwarder object.
        Caller must call stop() on object when finished
        """
        logger = logging.getLogger('sshtunnel')
        logger.setLevel(logging.ERROR)

        try:
            self._server = SSHTunnelForwarder((host, host_port),
                    ssh_username=username, ssh_private_key=key_file,
                    remote_bind_address=('127.0.0.1', remote_port), logger=logger)
        except sshtunnel.BaseSSHTunnelForwarderError as e:
            raise self.TunnelException(e)


    def connect(self):
        self._server.start()
        self.local_port = self._server.local_bind_port

    def close(self):
        self._server.stop()

    def __enter__(self):
        self.connect()
        return self

    def __exit__(self, type, value, traceback):
        self.close()
开发者ID:balramr,项目名称:clusterous,代码行数:33,代码来源:helpers.py

示例2: on_Btn_cups_clicked

 def on_Btn_cups_clicked(self, widget, ip, usuario, password, puerto, notebook, spinner, estado):
     ssh_path = os.environ['HOME'] + '/.ssh/id_rsa'
     spinner.start()
     estado.set_text("Creando tunel...")
     puerto = int(puerto)
     try:
         #Borra en el archivo cupsd.conf la autentificacion
         with settings(host_string=ip, port=puerto, password=password, user=usuario):
             sudo('sed -i."old" "/Require user @SYSTEM/d" /etc/cups/cupsd.conf;sed -i."old2" "/AuthType Default/d" /etc/cups/cupsd.conf;/etc/init.d/cups reload')
         server = SSHTunnelForwarder((ip, puerto), ssh_username=usuario, ssh_private_key=ssh_path, remote_bind_address=('127.0.0.1', 631))
         server.start()
         puerto_local = str(server.local_bind_port)
         scrolledwindow = Gtk.ScrolledWindow()
         scrolledwindow.set_hexpand(True)
         scrolledwindow.set_vexpand(True)
         page = WebKit.WebView()
         page.set_border_width(10)
         page.open("http://127.0.0.1:" + puerto_local)
         scrolledwindow.add(page)
         tab_label = tablabel.TabLabel("CUPS " + ip, Gtk.Image.new_from_file("/usr/share/grx/icons/cups32.png"))
         tab_label.connect("close-clicked", tablabel.on_close_clicked, notebook, page)
         notebook.append_page(scrolledwindow, tab_label)
         self.show_all()
     except:
         self.mensaje("No se ha podido ejecutar cups", "Atencion", atencion)
     spinner.stop()
     estado.set_text("")
开发者ID:aavidad,项目名称:grx-asistencia,代码行数:27,代码来源:equipos_linux.py

示例3: create_ssh_tunnel

    def create_ssh_tunnel(self, tunnel_password):
        """
        This method is used to create ssh tunnel and update the IP Address and
        IP Address and port to localhost and the local bind port return by the
        SSHTunnelForwarder class.
        :return: True if tunnel is successfully created else error message.
        """
        # Fetch Logged in User Details.
        user = User.query.filter_by(id=current_user.id).first()
        if user is None:
            return False, gettext("Unauthorized request.")

        if tunnel_password is not None and tunnel_password != '':
            try:
                tunnel_password = decrypt(tunnel_password, user.password)
                # Handling of non ascii password (Python2)
                if hasattr(str, 'decode'):
                    tunnel_password = \
                        tunnel_password.decode('utf-8').encode('utf-8')
                # password is in bytes, for python3 we need it in string
                elif isinstance(tunnel_password, bytes):
                    tunnel_password = tunnel_password.decode()

            except Exception as e:
                current_app.logger.exception(e)
                return False, "Failed to decrypt the SSH tunnel " \
                              "password.\nError: {0}".format(str(e))

        try:
            # If authentication method is 1 then it uses identity file
            # and password
            if self.tunnel_authentication == 1:
                self.tunnel_object = SSHTunnelForwarder(
                    (self.tunnel_host, int(self.tunnel_port)),
                    ssh_username=self.tunnel_username,
                    ssh_pkey=get_complete_file_path(self.tunnel_identity_file),
                    ssh_private_key_password=tunnel_password,
                    remote_bind_address=(self.host, self.port)
                )
            else:
                self.tunnel_object = SSHTunnelForwarder(
                    (self.tunnel_host, int(self.tunnel_port)),
                    ssh_username=self.tunnel_username,
                    ssh_password=tunnel_password,
                    remote_bind_address=(self.host, self.port)
                )

            self.tunnel_object.start()
            self.tunnel_created = True
        except BaseSSHTunnelForwarderError as e:
            current_app.logger.exception(e)
            return False, "Failed to create the SSH tunnel." \
                          "\nError: {0}".format(str(e))

        # Update the port to communicate locally
        self.local_bind_port = self.tunnel_object.local_bind_port

        return True, None
开发者ID:asheshv,项目名称:pgadmin4,代码行数:58,代码来源:server_manager.py

示例4: sshtunnel

def sshtunnel():
    server = SSHTunnelForwarder(
            (current_app.config['SSH_HOST'],current_app.config['SSH_PORT']),
            ssh_username=current_app.config['SSH_USER'],
            ssh_password=current_app.config['SSH_PASSWORD'],
            remote_bind_address=(current_app.config['SSH_REMOTE_HOST'], current_app.config['SSH_REMOTE_PORT'])
            )
    server.start()

    return server.local_bind_port
开发者ID:ZUNbado,项目名称:pybearmon,代码行数:10,代码来源:sql.py

示例5: TunelSSH

class TunelSSH():
    def __init__(self, ssh_address, ssh_port, ssh_username, ssh_password, remote_bind_address, remote_bind_port):
        self.server = SSHTunnelForwarder(ssh_address=(ssh_address, ssh_port), ssh_username=ssh_username, 
            ssh_password=ssh_password, remote_bind_address=(remote_bind_address, remote_bind_port))

    def Iniciar(self):
        self.server.start()
        return self.server.local_bind_port

    def Cerrar(self):
        self.server.stop()
开发者ID:procamora,项目名称:Librerias-Varias,代码行数:11,代码来源:ssh_forward.py

示例6: on_Btn_vncviewer_clicked

    def on_Btn_vncviewer_clicked(self, widget, ip, usuario, puerto, password, clave_remoto, spinner, estado):
        spinner.start()
        estado.set_text("Conectando con el equipo")
        ssh_path=os.environ['HOME'] + '/.ssh/id_rsa'

        try:
            puerto = int(puerto)
            server = SSHTunnelForwarder((ip, puerto), ssh_username=usuario,ssh_private_key=ssh_path,remote_bind_address=(ip, 5900))
            server.start()
            puerto_local = str(server.local_bind_port)
            msg = local('echo "' + clave_remoto + '" | vncviewer -autopass -compresslevel 9 -bgr233 127.0.0.1:' + puerto_local + ' &')
            #msg=local('echo "'+clave_remoto+'" | vinagre -autopass -compresslevel 9 -bgr233 127.0.0.1:'+puerto_local+' &')
        except:
            self.mensaje("No se ha podido ejecutar 'vncviewer' en el equipo remoto", "Atencion", atencion)
        spinner.stop()
        estado.set_text("")
开发者ID:aavidad,项目名称:grx-asistencia,代码行数:16,代码来源:equipos_linux.py

示例7: dal_connect

def dal_connect():
    server = SSHTunnelForwarder(
             (settings.ssh_host, settings.ssh_port),
             ssh_password=settings.ssh_password,
             ssh_username=settings.ssh_username,
             remote_bind_address=('127.0.0.1', 3306))

    server.start()

    uri = 'mysql://{username}:{password}@127.0.0.1:{port}/{db}'.format(
           username = settings.mysql_username,
           password = settings.mysql_password,
           db = settings.mysql_dbname,
           port = server.local_bind_port
        )

    db = DAL(uri, migrate = False)
    return db
开发者ID:62mkv,项目名称:py-redmine-helper,代码行数:18,代码来源:redmine_pydal.py

示例8: create_tunnel_to_cdh_manager

 def create_tunnel_to_cdh_manager(self, local_bind_address='localhost', local_bind_port=7180, remote_bind_port=7180):
     self._local_bind_address = local_bind_address
     self._local_bind_port = local_bind_port
     self.cdh_manager_tunnel = SSHTunnelForwarder(
         (self._hostname, self._hostport),
         ssh_username=self._username,
         local_bind_address=(local_bind_address, local_bind_port),
         remote_bind_address=(self.extract_cdh_manager_host(), remote_bind_port),
         ssh_private_key_password=self._key_password,
         ssh_private_key=self._key
     )
开发者ID:butla,项目名称:apployer,代码行数:11,代码来源:cdh_utilities.py

示例9: port_forward

 def port_forward(self, port=PORT):
     key = paramiko.RSAKey.from_private_key_file(
         config.get('EC2', 'PrivateKeyFile')
     )
     self._forward = SSHTunnelForwarder(
         ssh_address=(self.ip, 22),
         ssh_username=config.get('EC2', 'User'),
         ssh_private_key=key,
         remote_bind_address=('127.0.0.1', PORT),
         local_bind_address=('127.0.0.1', PORT)
     )
     self._forward.start()
开发者ID:ralph-group,项目名称:mucloud,代码行数:12,代码来源:mucloud.py

示例10: _portforward_agent_start

 def _portforward_agent_start(self):
     """Setup local port forward to enable communication with the Needle server running on the device."""
     self.printer.debug('{} Setting up port forwarding on port {}'.format(Constants.AGENT_TAG, self._agent_port))
     localhost = '127.0.0.1'
     self._port_forward_agent = SSHTunnelForwarder(
         (self._ip, int(self._port)),
         ssh_username=self._username,
         ssh_password=self._password,
         local_bind_address=(localhost, self._agent_port),
         remote_bind_address=(localhost, self._agent_port),
     )
     self._port_forward_agent.start()
开发者ID:mwrlabs,项目名称:needle,代码行数:12,代码来源:device.py

示例11: _portforward_frida_start

 def _portforward_frida_start(self):
     """Setup local port forward to enable communication with the Frida server running on the device."""
     self.printer.debug('{} Setting up port forwarding on port {}'.format("[FRIDA]", Constants.FRIDA_PORT))
     localhost = '127.0.0.1'
     self._frida_server = SSHTunnelForwarder(
         (self._ip, int(self._port)),
         ssh_username=self._username,
         ssh_password=self._password,
         local_bind_address=(localhost, Constants.FRIDA_PORT),
         remote_bind_address=(localhost, Constants.FRIDA_PORT),
     )
     self._frida_server.start()
开发者ID:mwrlabs,项目名称:needle,代码行数:12,代码来源:device.py

示例12: get_connection_params

 def get_connection_params(self):
     kwargs = super(DatabaseWrapper, self).get_connection_params()
     host = kwargs['host']
     port = kwargs['port']
     config = self.settings_dict["TUNNEL_CONFIG"]
     config['remote_bind_address'] = (host, port)
     self.tunnel = SSHTunnelForwarder(**config)
     self.tunnel.daemon_forward_servers = True
     self.tunnel.daemon_transport = True
     self.tunnel.start()
     kwargs["host"] = '127.0.0.1'
     kwargs['port'] = self.tunnel.local_bind_port
     return kwargs
开发者ID:DrWrong,项目名称:django_extra,代码行数:13,代码来源:base.py

示例13: __init__

    def __init__(self, host, username, key_file, remote_port, host_port=nat_ssh_port_forwarding):
        """
        Returns tuple consisting of local port and sshtunnel SSHTunnelForwarder object.
        Caller must call stop() on object when finished
        """
        logger = logging.getLogger('sshtunnel')
        logger.setLevel(logging.ERROR)

        try:
            self._server = SSHTunnelForwarder((host, host_port),
                    ssh_username=username, ssh_private_key=key_file,
                    remote_bind_address=('127.0.0.1', remote_port), logger=logger)
        except sshtunnel.BaseSSHTunnelForwarderError as e:
            raise self.TunnelException(e)
开发者ID:balramr,项目名称:clusterous,代码行数:14,代码来源:helpers.py

示例14: DatabaseWrapper

class DatabaseWrapper(MysqlDatabaseWrapper):

    def __init__(self, *args, **kwargs):
        super(DatabaseWrapper, self).__init__(*args, **kwargs)
        self.tunnel = None

    def get_connection_params(self):
        kwargs = super(DatabaseWrapper, self).get_connection_params()
        host = kwargs['host']
        port = kwargs['port']
        config = self.settings_dict["TUNNEL_CONFIG"]
        config['remote_bind_address'] = (host, port)
        self.tunnel = SSHTunnelForwarder(**config)
        self.tunnel.daemon_forward_servers = True
        self.tunnel.daemon_transport = True
        self.tunnel.start()
        kwargs["host"] = '127.0.0.1'
        kwargs['port'] = self.tunnel.local_bind_port
        return kwargs

    def _close(self):
        super(DatabaseWrapper, self)._close()
        if self.tunnel is not None:
            self.tunnel.stop()
开发者ID:DrWrong,项目名称:django_extra,代码行数:24,代码来源:base.py

示例15: __init__

 def __init__(self):
     ssh_tunnel = Credentials.ssh_tunnel
     db_config = Credentials.vicnode_db
     self._server = SSHTunnelForwarder(
         ((ssh_tunnel['host']), (int(ssh_tunnel['port']))),
         ssh_password=ssh_tunnel['ssh_password'],
         ssh_username=(ssh_tunnel['username']),
         ssh_pkey=(ssh_tunnel['private_key_file']),
         remote_bind_address=(db_config['host'], 5432),
         allow_agent=False
     )
     self._server.start()
     # we are about to bind to a 'local' server by means of an ssh tunnel
     # ssh tunnel: which will be seen as a local server...
     # so replace the loaded config host
     db_config['host'] = 'localhost'
     db_config['port'] = self._server.local_bind_port
     self._db_connection = psycopg2.connect(**db_config)
     self._db_cur = self._db_connection.cursor(
         cursor_factory=psycopg2.extras.RealDictCursor)
     self.test_connection()
开发者ID:MartinPaulo,项目名称:ReportsAlpha,代码行数:21,代码来源:bc_storage.py


注:本文中的sshtunnel.SSHTunnelForwarder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。