您好,我遇到了一个问题,即队列未按应有的顺序打印项目,因此它不检查所有密码。下面的代码
Class ZipFile:
def __init__(self):
self.zip_file = self.return_zip_file() # just grabbing the zip file here
self.password_word_list = self.password_file() # grabbing the password file
self.q = queue.Queue(maxsize=50) # making the queue here
def word_list(self):
with open(self.password_word_list, "r") as f:
data = f.readlines()
for password in data:
password = password.strip()
yield password
def extract_zip_file(self, zip_file, password):
try:
zip_file.extractall(pwd=password.encode()) # extracting zip
print(f"[+] Password -> {password}")
except Exception as e:
print(e) # for debugging
pass
def brute_force_zip(self)
get_word_list = self.word_list()
count = 0
get_zip_file = zipfile.ZipFile(self.zip_file)
for password in get_word_list:
self.q.put(password)
if self.qsize() == 50:
while not self.q.empty():
thread = Process(target=self.extract_zip_file, args=(get_zip_file, self.q.get()), daemon=True)
thread.start()
count += 1
print(f"\rAttempts: {str(count)}")
因此,基本上self.q.get()会无序打印所有内容,有时甚至不会得到所有单词,我该如何解决?谢谢!
实际上,我发现了这一点,却忘记了多处理正在处理不同的线程,这就是原因。