Skip to main content

Initiate SSH tunnels in the background

Project description

bgtunnel - Initiate SSH tunnels in the background
Useful when you need to connect to a database only accessible through
another ssh-enabled host. It works by opening a port forwarding ssh
connection in the background, using threads. The connection(s) are
automatically closed when the process exits, or when explicitly calling
the `close` method of the returned SSHTunnelForwarderThread object.

Notes on default values

* Bind address and host address defaults to ""
* SSH port defaults to 22
* Bind port defaults to picking a random available one, accessible from the
object returned by the `open` function

Usage examples

# Enable forwarding for a MS SQL server running on the remote SSH host
>>> import bgtunnel
>>> forwarder ='manager', ssh_address='',
... host_port=1433)
>>> print(forwarder.bind_port)
>>> import somesqlpkg
>>> conn = somesqlpkg.connect('mssql://myuser:mypassword@localhost:' +

# Enable forwarding for an old AS400 DB2 server accessible only via
# the remote SSH host. Multiple ports need to be opened.
>>> import bgtunnel
>>> ports = [446, 449] + range(8470, 8477)
>>> forwarders = []
>>> for port in ports:
... forwarders.append('manager',
... ssh_address='',
... host_port=port, bind_port=port))
>>> print('
'.join(f.bind_port for f in forwarders))
>>> import somesqlpkg
>>> conn = somesqlpkg.connect('mssql://myuser:mypassword@localhost:446')

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bgtunnel, version 0.4.1
Filename, size File type Python version Upload date Hashes
Filename, size bgtunnel-0.4.1-py2.py3-none-any.whl (8.4 kB) File type Wheel Python version 3.5 Upload date Hashes View
Filename, size bgtunnel-0.4.1.tar.gz (7.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page