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 "127.0.0.1"
* SSH port defaults to 22
* Local 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 = bgtunnel.open(ssh_user='manager', ssh_address='1.2.3.4',
... bind_port=1433)
>>> print(forwarder.host_port)
59432
>>> import somesqlpkg
>>> conn = somesqlpkg.connect('mssql://myuser:mypassword@localhost:' +
forwarder.port)

# 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, 8470, 8471, 8472, 8473, 8474, 8475, 8476)
>>> forwarders = []
>>> for port in ports:
... forwarders.append(bgtunnel.open(ssh_user='manager',
... ssh_address='1.2.3.4',
bind_address='192.168.0.5',
... bind_port=port, host_port=port))
>>> print(*tuple(f.host_port for f in forwarders))
446
449
8470
8471
8472
8473
8474
8475
8476
>>> 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.

Source Distribution

bgtunnel-0.2.1.tar.gz (6.0 kB view details)

Uploaded Source

File details

Details for the file bgtunnel-0.2.1.tar.gz.

File metadata

  • Download URL: bgtunnel-0.2.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bgtunnel-0.2.1.tar.gz
Algorithm Hash digest
SHA256 de9a4359c55246e8533fb2d4de21b80e8de7ac3ec3953cae303233d43d149092
MD5 c715d00478726469ea4a0544eade915b
BLAKE2b-256 47364affaf6b3a84345554c19bf5ba32cc3f19c9c1a71090294ab8ad12564cb3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page