首页 > 解决方案 > How to fix connection error when trying to create an SSH tunnel in Python whilst running Nord VPN for Windows

问题描述

This is perhaps an unusual question, in that I know my code works!

In short, I am trying to create an SSH tunnel with Python (using the sshtunnel and paramiko libraries).

This code works fine if I turn off the Nord VPN for Windows client that I am running on my local machine, however (perhaps unsurprisingly) when this is turned on the SSH tunnel doesn't connect.

In the Nord VPN client, I can set up split tunnelling for .exe files only, so there I can list SSH and manually SSH even when the client is running.

So is anyone aware of a work around here, where I can either bypass Nord VPN programmatically, or any other suggestions that may assist (I have tried the usual suggestions such as changing protocol to OpenVPN and disabling the CyberSec in the Nord VPN client GUI)?


def ssh_tunnel():

    EC2_URL = IP_ADDRESS
    username = "USER_NAME"
    pem_file = 'FILE_NAME.pem'

    # Create the tunnel
    server = SSHTunnelForwarder(
        (EC2_URL, yyyy),
        ssh_username=username,
        ssh_pkey=pem_file,
        remote_bind_address=(EC2_URL, xxxx),
        local_bind_address=('xx.x.x.x', xxxx)
    )
    # Starts the tunnel
    server.start()

    # Prints the local bind port
    print(server.local_bind_port)

    # Closes the tunnel
    server.stop()

Just in case it helps, here is the actual error (although I'm guessing given the problem is known it might not add too much)!

2021-04-26 18:20:54,319| ERROR   | Could not connect to gateway x.x.x.x:x : Unable to connect to x.x.x.x: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Traceback (most recent call last):
  File "xxx.py", line 284, in <module>
    ssh_tunnel()
  File "xxx.py", line 201, in ssh_tunnel
    server.start()
  File "xxx\lib\site-packages\sshtunnel.py", line 1331, in start
    self._raise(BaseSSHTunnelForwarderError,
  File "xxx\lib\site-packages\sshtunnel.py", line 1174, in _raise
    raise exception(reason)
sshtunnel.BaseSSHTunnelForwarderError: Could not establish session to SSH gateway

标签: pythonsshvpnssh-tunnel

解决方案


推荐阅读