Last active
April 13, 2017 15:56
-
-
Save twkang/9676416 to your computer and use it in GitHub Desktop.
ssh connection to server behind socks5 proxy : using socksipy(https://code.google.com/p/socksipy-branch/) and paramiko(https://github.com/paramiko/paramiko)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import paramiko | |
| import socks | |
| class SSH(object): | |
| def __init__(self, host, port, server_encoding): | |
| socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, host, port, False) | |
| paramiko.client.socket.socket = socks.socksocket | |
| self.SERVER_ENCODING = server_encoding | |
| def create_connection(self, host, port, username, password): | |
| self._ssh = paramiko.SSHClient() | |
| self._ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
| self._ssh.connect(hostname=host, port=port, username=username, password=password) | |
| self.chan = self._ssh.invoke_shell() | |
| self.chan.settimeout(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment