扭曲的反向代理阻止了一些ips

时间:2018-08-30 14:00:47

标签: python twisted ipv4 blacklist

我已经使用twisted构建了一个简单的反向代理,以便可以阻止一些请求到达我的服务器。检查URI可以正常工作,但是我还想添加一个ipv4黑名单。

我如何检查连接到我的代理服务器的IP并最终重新连接?

到目前为止,这是我的代码:

class BadURL(Resource):
    def render(self, request):
    return ""
class HTTPSReverseProxyResource(proxy.ReverseProxyResource, object):
    def getChild(self, path, request):

    if some logic:
            return BadURL()
    child = super(HTTPSReverseProxyResource, self).getChild(path, request)
    return HTTPSReverseProxyResource(child.host, child.port, child.path,
                                     child.reactor)


if __name__ == '__main__':

    ap = argparse.ArgumentParser()
    ap.add_argument('-c', type=str)
    ap.add_argument('-k', type=str)
    ns = ap.parse_args()

    myProxy = HTTPSReverseProxyResource('localhost', 4443, '')

    site = server.Site(myProxy)


    reactor.listenTCP(8080, site, interface='192.168.58.1')
    reactor.run()

0 个答案:

没有答案
相关问题