python - 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
解决方案
推荐阅读
- arrays - 如何从char数组中提取数字并将它们相加
- python-3.x - 使用 Python RDFLib 解释 .ttl 文件中的链接数据的工作流程
- python - Python海龟赛重启功能
- docker - 带有 consul 和 docker swarm EE 的服务网格
- ejabberd - Ejabberd STUN 问题:未知模块 mod_stun_disco 无法启动
- bash - 使用一行 shell 命令编辑 dhcpd.conf 文件
- java - 将通配符传递给进程构建器
- firebase-realtime-database - 如何克服 Firebase 实时数据库规则中的级联?
- c++ - 双舍入误差,即使使用 DBL_DIG
- node.js - @fullcalendar/google-calendar 与“gatsby build”中断