图片-稻子网
图片-稻子网
图片-稻子网
图片-稻子网

Python3基于PySocks,paramiko来使用socks代理连接SSH服务器

==SSHClient 封装Transport==

import paramiko, socks
sock = socks.socksocket()
host, port = '103.67.206.10', 11113
sock.set_proxy(proxy_type=socks.SOCKS5,addr=host,port=port,username='lx',password='Qaz123')
sock.connect(('10.200.124.37', 33899))
private_key = paramiko.RSAKey.from_private_key_file('/root/.ssh/starsliao-gmt')
transport = paramiko.Transport(sock)
transport.connect(username='www', pkey=private_key)
ssh = paramiko.SSHClient()
ssh._transport = transport
stdin, stdout, stderr = ssh.exec_command('df')
print(stdout.read())
transport.close()
sock.close()

==基于公钥秘钥连接==

import paramiko, socks
sock = socks.socksocket()
host, port = '103.67.206.10', 11113
sock.set_proxy(proxy_type=socks.SOCKS5,addr=host,port=port,username='lx',password='Qaz123')
sock.connect(('10.200.124.37', 33899))
private_key = paramiko.RSAKey.from_private_key_file('/root/.ssh/starsliao-gmt')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='10.200.124.37', port=33899, username='www', pkey=private_key, sock=sock)
stdin, stdout, stderr = ssh.exec_command('df')
print(stdout.read())
ssh.close()
sock.close()
© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片