Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- __author__ = 'zerubits'
- #need an ssh account and squid proxy for this
- sshname = ''
- sshport = 22
- username = ''
- password = ''
- remoteproxy = ''
- remoteport =
- ssh = paramiko.SSHClient()
- ssh.load_system_host_keys()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(sshname,sshport,username=username,password=password)
- print('ssh client connected to {}:{}'.format(sshname,sshport))
- transport = ssh.get_transport()
- for i in range(50):
- try:
- payload = 'CONNECT 0.facebook.com:80 HTTP/1.0\r\n\r\n'
- channel = transport.open_channel('direct-tcpip',src_addr=('localhost',1301),dest_addr=(remoteproxy,remoteport))
- channel.sendall(payload.encode())
- response = channel.recv(1024)
- print(response) #expected response(b'HTTP/1.0 200 Connection established\r\n\r\n')
- channel.close()
- except Exception as error:
- print(error)
- transport.close()
- ssh.close()
- """
- full error caught by sys.exc_info()
- Socket exception: An existing connection was forcibly closed by the remote host (10054)
- b''
- (<class 'paramiko.ssh_exception.SSHException'>, SSHException('SSH session not active'), <traceback object at 0x00000205856BCA08>)
- full logged error by logging
- ERROR:paramiko.transport:Socket exception: An existing connection was forcibly closed by the remote host (10054)
- ERROR:__main__:SSH session not active
- Traceback (most recent call last):
- File "C:\Users\CDN-deco\Desktop\xconnect.py", line 325, in <module>
- channel = transport.open_channel('direct-tcpip',src_addr=('localhost',1301),dest_addr=(remoteproxy,remoteport))
- File "C:\Users\CDN-deco\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 854, in open_channel
- raise SSHException('SSH session not active')
- paramiko.ssh_exception.SSHException: SSH session not active
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement