检索客户端的IP地址(或尽最大努力)

sanic-ipware的Python项目详细描述


这是与Sanic一起工作的django-ipware叉。

概述

在保持客户端的IP地址dry的同时,尝试获取客户端的IP地址

注意

没有真正好的“开箱即用”的解决方案来对付假IP地址,也就是“IP地址欺骗”。我们鼓励您阅读本页的Advanced users部分,并使用trusted_proxies_ips和/或proxy_count功能来满足您的需要,特别是如果您计划在任何与身份验证、安全或“反欺诈”相关的体系结构中包含sanic-ipware

如何安装

安装sanic-ipware的最佳方法是使用pip

pip install sanic-ipware

如何使用

基本上有一个方法可以从sanic_ipware使用,叫做get_client_ip。结果是Tuple[Optional[str], bool](ipaddr, routable)

fromsanic_ipwareimportget_client_ip@app.get("/some/handler")asyncdefsomehandler(request):ip,routable=get_client_ip(request)ifipisnotNone:ifroutable:# we have a (probably) real, public ip address for userelse:# we have ip address, but it might not be public routableelse:# we don't have a ip address for the user

高级用户

# you can provide your own meta precedence order by using the# request_header_order in the function call:ip,routable=get_client_ip(request,request_header_order=['Forwarded-For','X-Forwarded-For'])# if you're going to do this a lot, wrap the function somewhere with# functools.partialfromfunctoolsimportpartialmy_get_client_ip=partial(get_client_ip,request_header_order=['Forwarded-For','X-Forwarded-For'])ip,routable=my_get_client_ip(request)# if you plan to use sanic_ipware in any authentication, security or# "anti-fraud" related architecture, you should configure it to only# "trust" one or more "known" proxy server(s)), in the function call:ip,routable=get_client_ip(request,proxy_trusted_ips=['198.84.193.158'])# you can perform the same functools.partial trick with these trusted IPs

许可证

mit,与django-ipwarelicense相同。

变更日志

2018年9月28日v0.1.0

  • pypi上的第一个版本。不稳定。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java FloatingAction按钮与RecyclerView中的CardView重叠   java如何计算CardLayout中的卡数   从远程系统上传MySQL数据库并访问Java应用程序   java调用堆栈如何处理带或不带返回类型的递归?   Springboot中的java组计数聚集   java如何在javafx textarea中使用richtextfx   获取与Mockito相关的错误时出现Java问题   java如何将JaxRS响应转换为Wiremock响应   Hadoop集群java。net ConnectionException:连接被拒绝错误   java如何加载文件私有文件类型是pem   java在元空间中的提升和加载的类   如何将系统属性传递给从HTML启动的Java小程序   java如何从网页中获取值并在主类中使用它?安卓应用   java在春天,advisor和aspect之间有什么区别?   java如何检测文件是否已重命名?   java消息驱动Bean何时使用