【发布时间】:2017-01-20 05:44:33
【问题描述】:
我在 heroku 上有一个 Bottle 应用,我需要过滤入站 IP 地址。我不太清楚如何做到这一点。
This answer 建议使用包装器,但这是用于私有路由 - 不过滤入站请求。包装是:
def private_only(route):
def wrapper(*args, **kwargs):
if IPy.IP(bottle.request.remote_addr).iptype() == 'PRIVATE':
return route(*args, **kwargs)
else:
return "Not allowed!"
return wrapper
将包装器更改为:
def private_only(route):
def wrapper(*args, **kwargs):
if IPy.IP(bottle.request.remote_addr).iptype() in ALLOWED_IPS:
return route(*args, **kwargs)
else:
return "Not allowed!"
return wrapper
并使用以下方法装饰路线:
@route('/my/internal/route')
@private_only
def my_view():
return some_data()
工作?
【问题讨论】:
标签: python routing ip filtering bottle