python多进程爆破验证码

推荐在linux环境下使用,找到之后可以使用信号量signal,Ctrl + C可以退出所有进程.

import os
import string
from multiprocessing import Pool
import random
import hashlib
import signal

signal.signal(signal.SIGINT , signal.SIG_DFL)
signal.signal(signal.SIGHUP , signal.SIG_DFL)

def md5(data):
    return hashlib.md5(data).hexdigest()

def getRandomStr():
    return "".join(random.sample(string.ascii_letters + string.digits ,8))

EXIT_FLAG = False

def force(x):
    global EXIT_FLAG
    # print(x)
    print(os.getpid())
    while not EXIT_FLAG:
        data = getRandomStr()
        s = md5(data.encode())
        if s[-6:] == "a5ec49":
            print(data,s)
            EXIT_FLAG = True
    return True

if __name__ == '__main__':
    with Pool(5) as p:
        p.map(force , range(5))

你可能感兴趣的