Defense DDOS Script in Python

This blind can say that the opening of the white can save, the reason why is DDOS, not because the mad dog is chased, but because the traffic is full of simplecd after the VC tragedy.

Not only that, some fans are grabbing, some fans are downloaded with Thunder, and the port of 100Mbps actually has a full load for more than a dozen hours. What is this concept? 100Mbps full load 1 day, the traffic is 1000g, so don’t take long, I can wait for the ticket for the hundred knives, tears.

In addition, the speed of 100 Mbps makes the hard disk can’t turn, and severely dragging down the response speed of the website, I want to die, I want to die. I wanted to hang a day in the year, and the guys who were captured and got a short-term (where those guys included me, sweat). SimpleCD can’t support it.

In fact, this kind of human flesh DDOS is more difficult to distinguish more than normal DDOS, but it can only do personnel, listen to life, refer to some articles written a script of Python from preventing DDOS, and add CRON per minute.

The principle of realization is to query the number of connections of NetStat, with IPTables to enable it for a certain period of time, automatic ban, automatic unifferent.

The following is the code snippet:

From ProBProcessimportPopen, Pipe






#initializing) and (notip.startswith (“192.168”):

OUTPOPEN (“Iptables-IINPUT-S% S-JDROP”% IP, Shelltrue, BufSize1024, StdoutPipe) .stdout

Print “Blocking% SFOR% svisits”% (IP, Count)

C.EXECUTE (‘Replaceintoddosvalues ??(?,?), (IP, INT (Time.Time ())))))))))))))

Time.sleep (0.1)

db.commit ()


C.EXECUTE (“Select * fromDDOS”)

DDosc.FetChall ()

Forip, DateindDos:

ifdate + Outdate_time


Print “Unblocking% S”% IP

Outpopen (“iptables-dinput-s% s-jdrop”% ip, shelltrue, buffsize1024, stdoutpipe) .stdout

Time.sleep (0.1)

Db.commit () The effect of this script is 0, it is more than 500 people, but it is still full speed, it is terrible.

Updated 24 days:

At the same time, using this script, the spin of the desktop version of the site to a 10M unlimited place, it seems that the world is too peaceful (?)