import paramiko
from sshtunnel import SSHTunnelForwarder

remote_host = "10.0.3.3"
username = "dylan"
local_port = 2222
remote_port = 22

# Create SSH tunnel to remote host, forward local port 22 to remote port 2222
print("Creating SSH tunnel")
with SSHTunnelForwarder((remote_host, remote_port),ssh_username="dylan", ssh_password="!",
                        local_bind_address=("127.0.0.1", local_port),
                        remote_bind_address=(remote_host, remote_port)) as tunnel:
    print(tunnel.local_bind_port)
    # Login to newly created tunnel and send some commands
    print("SSH tunnel successfully created. Authenticating..")
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
    client.connect("127.0.0.1", local_port, password="!")
    # Do client operations here
    client.close()

print("Program ran successfully")
