限制IP地址以访问GAE上的应用程序?

时间:2015-03-03 08:30:21

标签: python google-app-engine

我在GAE上有一个应用程序。假设我希望该应用程序可用于172.12。 IP地址。我怎么能这样做?

3 个答案:

答案 0 :(得分:4)

ip = self.request.remote_addr

if ip in allowed_ip_list:
    allow_access = True
else:
    allow_access = False

更详细的答案:Get IP address in Google App Engine + Python

答案 1 :(得分:0)

我知道它是一个旧帖子,但是对于参考:这是阻止IP的干净方法:https://cloud.google.com/appengine/docs/python/config/dos?csw=1

编辑:要完成答案,在python中您需要做的就是在应用程序的根目录中创建一个dos.yaml文件,并将要拒绝服务的ip或ip组添加到: blacklist: - subnet: 192.0.2.1 description: A single IPv4 address - subnet: abcd::123:4567 description: A single IPv6 address

然后确保通过运行appcfg.py update_dos <directory>

上传新条目

答案 2 :(得分:-1)

在Java中,最好通过Servlet过滤器来完成,如this Stack Overflow thread中所述。对于python,你可以自己编写一个任意的安全函数,正如另一个答案所说的那样。