0

我想在基于扭曲的应用程序中断开特定用户的连接。有人可以解释我该怎么做吗?

4

1 回答 1

1
from twisted.web import server, resource
from twisted.internet import reactor

bannedIPs = ["127.0.0.1"]

class HelloResource(resource.Resource):
    isLeaf = True
    numberRequests = 0

    def render_GET(self, request):
        clientIP = request.getClientIP()

        if clientIP in bannedIPs:
            return "you are banned"

        self.numberRequests += 1
        request.setHeader("content-type", "text/plain")
        return "I am request #" + str(self.numberRequests) + "\n"

reactor.listenTCP(8080, server.Site(HelloResource()))
reactor.run()
于 2012-04-15T15:03:33.290 回答