Comments (18)
Please update the sshtunnel package and retry.
from sshtunnel.
This is not possible. What you're trying to achieve is not connecting to the SSH gateway through a SOCKS5 proxy. There's no support for dynamic application-level port forwarding (equivalent to OpenSSH's client -D
option).
What you can do instead is a tunnel for a single destination, if that fulfils your requirements.
from sshtunnel.
If what you mean is how to make an ssh connection to a server behind a socks5 proxy, you may first create a proxy (i.e. with pysocks
) and pass it to sshtunnel
. I removed the restriction for the proxy
argument in SSHTunnelForwarder
so now any socket-like object may be used (see sock parameter information for more details).
import socks
SOCKS5_PROXY_HOST = '1.2.3.4'
SOCKS5_PROXY_PORT = 1080
s = socks.socksocket()
s.set_proxy(socks.SOCKS5, SOCKS5_PROXY_HOST, SOCKS5_PROXY_PORT)
tunnel = sshtunnel.SSHTunnelForwarder(
('ssh_server_ip', 22),
ssh_username='user',
ssh_password='secret',
remote_bind_address=('127.0.0.1', 5555),
ssh_proxy=s,
)
from sshtunnel.
I modified according you. but It not working?
Source code:
import sshtunnel
import socks
SOCKS5_PROXY_HOST = '127.0.0.1'
SOCKS5_PROXY_PORT = 1080
s = socks.socksocket()
s.set_proxy(socks.SOCKS5, SOCKS5_PROXY_HOST, SOCKS5_PROXY_PORT)
tunnel = sshtunnel.SSHTunnelForwarder(
('182.69.xxx.70', 22),
ssh_username='admin',
ssh_password='admin',
remote_bind_address=('127.0.0.1', 5555),
ssh_proxy=s,
)
tunnel.start()
#
print(tunnel.local_bind_port)
Error:
File "D:/data_sourcecode/Test/test.py", line 17, in <module>
tunnel.start()
File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\sshtunnel.py", line 1131, in start
self._create_tunnels()
File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\sshtunnel.py", line 1022, in _create_tunnels
self._connect_to_gateway()
File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\sshtunnel.py", line 1231, in _connect_to_gateway
self._transport = self._get_transport()
File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\sshtunnel.py", line 1000, in _get_transport
assert(isinstance(self.ssh_proxy, paramiko.proxy.ProxyCommand))
AssertionError
from sshtunnel.
I updated and tried then didn't show bug it. But It's not working( It's don't run to command line this
print(tunnel.local_bind_port)
)
from sshtunnel.
Yeap, I think I know where the error is. Could you please re-update (from source, not pypi) and retry?
from sshtunnel.
Still error:
Traceback (most recent call last):
File "D:/data_sourcecode/Test/test.py", line 20, in <module>
tunnel.start()
File "build\bdist.win-amd64\egg\sshtunnel.py", line 1152, in start
File "build\bdist.win-amd64\egg\sshtunnel.py", line 1043, in _create_tunnels
File "build\bdist.win-amd64\egg\sshtunnel.py", line 1252, in _connect_to_gateway
File "build\bdist.win-amd64\egg\sshtunnel.py", line 1029, in _get_transport
File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\socks.py", line 687, in connect
raise ProxyConnectionError(msg, error)
socks.ProxyConnectionError: Error connecting to SOCKS5 proxy 127.0.0.1:1080: [Errno 10061] No connection could be made because the target machine actively refused it
from sshtunnel.
That seems more like a local issue. It's working as expected with a socks proxy set up with openssh.
[...] the target machine actively refused it
from sshtunnel.
I don't understand why it not working. the target machine actively refused it
I want to download a mp3 file with socks5 and It must be download fast. Please help me and share for me a example code to do it.
Thanks
from sshtunnel.
@thehung12a3 the example already provided should be valid. At first that could not work because before 0.0.8.3
the proxy had to be a paramiko.Proxycommand
instance. Now this restriction is gone and any socket-like object may be used as proxy.
You may first try if you can access via your proxy with openssh:
$ ssh -o ProxyCommand='nc -x YOUR_PROXY_IP:YOUR_PROXY_PORT %h %p' \
SSH_SERVER_TARGET -L <...>
from sshtunnel.
I can not access via socks5 in firefox browser. When you release version0.0.8.3
?. I'm waiting it and hope all is well.
from sshtunnel.
Can you describe or make a draw of what you have at the moment? I'm not sure I'm understanding your problem properly. With the changes I already did I was able to achieve the following:
+---------+
1080 | |
| socks5 | 22+----------+ 443-----------+
+----------------> proxy +-----> SSH +----> Web |
<-----------------+ <-----+ server <----+ server |
| | | | ^ | |
| | +----------+ | +-----------+
| | |
+---------+ +
tunnel
The scenario in this diagram worked for me with the code pasted before.
from sshtunnel.
I run the above code snippets then It's still the occur attunnel.start()
File "C:\python-64bit\python-2.7.10.amd64\lib\site-packages\socks.py", line 687, in connect
raise ProxyConnectionError(msg, error)
socks.ProxyConnectionError: Error connecting to SOCKS5 proxy 127.0.0.1:1080: [Errno 10061] No connection could be made because the target machine actively refused it
I used pip to uninstall sshtunnel and install from new source. But not working?. I don't know how to fix it?
My scenario:
I will run the above code snippets to a connection with socks5. After that I open a firefox browser and access with socks5 to download a file mp3
from sshtunnel.
I still don't understand what's the role of the SSH tunnel here. Where is your proxy? (behind/in front of the SSH server), where's your web service (tunnelled/not tunnelled over the SSH tunnel)?
A picture is worth a thousand words BTW.
from sshtunnel.
I wanted it to be like this. https://www.youtube.com/watch?v=COg_LB4Fe5o
from sshtunnel.
hi
please help create socks5 with ssh auto login
from sshtunnel.
@fernandezcuesta I came here when looking for an ssh -D
equivalent aka SOCKS over SSH tunnel in python. Above, in 2016, you stated that this is not supported. However, you did not state any reason or rationale why it isn't or might not be added in the future.
Can you please explain a bit why this is not supported yet, how this might be implemented and if you would like to see contributions towards it?
from sshtunnel.
Hi there. The idea was to keep it as simple as possible and not expend much time supporting what you can achieve with other packages (e.g. asyncssh).
Anyway feel free to contribute, it'll be more than welcome.
from sshtunnel.
Related Issues (20)
- SSH tunnels stop working after some time HOT 12
- UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long) HOT 1
- SSHTunnel able to log in even with wrong credentials HOT 1
- opentunnel with -N parameter
- Add types and type checking so mypy type checking is happy
- Modern packaging HOT 1
- sshtunnel not working with python 3.9 HOT 1
- An example with requests library
- sshtunnel not working. keeps showing ERROR | Password is required for key HOT 1
- Hello, how would I run this portforward command with sshtunnel
- SSHTunnelForwarder cannot be found HOT 1
- Local Machine is not able to connect to the tunnel HOT 1
- Exception (client): Incompatible ssh server (no acceptable ciphers)
- Tunnel forward from local network device to VPS HOT 1
- ~/.ssh/config Include directive being ignored
- BUG: allow_agent isn't working. HOT 1
- port forwarder
- SSH-Key saved in 1Password HOT 1
- Unable to make connection to the database server when sslmode is "verify-full". HOT 1
- Silencing outut
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sshtunnel.