Python module that allows multi-hop SSH tunneling/port-forwarding
Project description
pytunneling
NOTE: This module is still in early development and may not be fully stable. Use at own risk.
Description
Python module that allows multi-hop SSH tunneling/port-forwarding.
While modules like Paramiko and sshtunnel provide excellent SSH and SSH tunnelling functionality (and is what is used under the hood for this module), neither directly support multi-hop SSH tunneling commonly required in heavily firewalled environments or complex network structure that may not have direct connectivity.
The logic to this module progressively creates tunnels (that use the previous tunnel if applicable) based on your input until the final tunnel is created which is what is reported as the localport for you to use as you please. This may look something like; desktop 22<>22 bastion1 22<>22 bastion2 22<>5432 database server. Refer to usage below.
Install
Pip
pip install pytunneling
Requirements
- Python 3.6 or greater
Usage
Import as Python module
Note: tunnel_info
argument expects a list of dictionary objects containing keyword arguments noted in the sshtunnel docs corresponding to the bastion "hops", with the actual destination IP and port being target_ip
and target_port
.
from pytunneling import TunnelNetwork
from time import sleep
tunnel_info = [
{"ssh_address_or_host": "bastion1",
"ssh_username": "sshuser",
"ssh_pkey": "~/.ssh/id_rsa", # Note this refers to a local file on the machine that runs logic
},
{"ssh_address_or_host": "bastion2",
"ssh_username": "sshuser",
"ssh_password": "somesecurepassword",
}
]
with TunnelNetwork(tunnel_info=tunnel_info, target_ip="database", target_port=5432) as tn:
print(tn.get_local_connect_port())
while True:
# Use this tunnel
sleep(5)
CLI
CLI Usage
Note: The CLI is not yet implemented
# TODO
CLI Examples
# TODO
Known Issues
- Currently this module will time out when an SSH thumbprint prompt appears (seen for first time SSH usage), be sure to validate SSH connection/credentials works. To investigate whether there is an option to accept or avoid this.
Contributing
Feel free to raise any feature requests/problems/improvements as issue or pull request via GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytunneling-0.0.1.tar.gz
.
File metadata
- Download URL: pytunneling-0.0.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57bfefa4595f0a05432ecb35bc120266b85168b8ce791e47769a0ff2e2611d6a |
|
MD5 | 5cb0c5dccda83d9d656ab5ddbd556c5b |
|
BLAKE2b-256 | 305dd2baed33348bf6a1182b9c860a81562b5d753ab8b246cf40a9450dce0e11 |
File details
Details for the file pytunneling-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pytunneling-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef2a3694652dbc049b11b11015cf9d8e5f4e602420ffefa9ce9ec344a95ca256 |
|
MD5 | 00d550f394c7160a55ec1c2c183a2fbb |
|
BLAKE2b-256 | 94463b37dcb9f185f7b572e8003769cade9ac08131dcb3a008e712bcbb4ad906 |