我想在基于扭曲的应用程序中断开特定用户。有人可以解释我怎么做吗?
答案 0 :(得分: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()