检索客户端的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中优雅地处理FileNotFoundexception   java线程卡在BlockingQueue上。无缘无故   类网格程序w/java   StrutsJava:动态应用Velocity脚本   java在运行时重写/禁用方面   java Apache POI无法正确读取Excel单元格中的秒数   具有不同用户权限的Java文件夹/文件创建   java我可以检查Firebase ValueEventListener onDataChanged是否已被调用吗?   尽管获得了用户权限,java Android开发文件权限仍被拒绝   java如何使用JPA映射map<EnumType,Double>?   java是否使用UI线程显示toast消息?   JAVAlang.IllegalArgumentException:不支持的元素:rss   java Android setRequestedOrientation活动和视图生命周期   安卓如何在Java中定义支票盒?   在Java中,对于大输入,字符串解析长期失败   使Java在XP中按计划任务运行读取env用户变量时出现问题   任务“:workflowsjava:NodeDriver”的梯度执行失败。main()   java如何检测是否只设置了部分属性?   在客户端web服务上使用JBossWS时,java无法找到/更改log4j的默认配置   java LibGDX写入文本文件并接收各种错误