码迷,mamicode.com
首页 > 编程语言 > 详细

python rforward.py

时间:2016-04-29 01:54:20      阅读:547      评论:0      收藏:0      [点我收藏+]

标签:python ssh

def main():
    options,server,remote = parse_options()
    password = None
    if options.readpass:
        password = getpass.getpass(‘Enter SSH password:‘)
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy())
    verbose(‘Connecting to ssh host %s:%d....‘ % (server[0],server[1]))
    try:
        client.connect(server[0],server[1],username=options.user,key_filename=options.keyfile,look_for_keys=options.look_for_keys,password=password)
    except Exception as e:
        print(‘*** Failed to connect to %s:%d:%r‘ % (server[0],server[1],e))
        exit(0)
    verbose(‘Now forwarding remote port %d to %s:%d...‘ % (options.port,remote[0],remote[1]))
    try:
        reverse_forward_tunnel(options.port,remote[0],remote[1],client.get_transport())
    except KeyboardInterrupt:
        print(‘C-c: Port forwarding stopped.‘)
        sys.exit(0)


本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1768812

python rforward.py

标签:python ssh

原文地址:http://jingshanls.blog.51cto.com/3357095/1768812

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!