Skip to content

Instantly share code, notes, and snippets.

@twkang
Last active April 13, 2017 15:56
Show Gist options
  • Select an option

  • Save twkang/9676416 to your computer and use it in GitHub Desktop.

Select an option

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)
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