GithubHelp home page GithubHelp logo

459217974 / ip2region Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 2.0 6.86 MB

根据IP查询IP地区的工具。使用了Cython优化了性能。结合Tornado可以实现自动更新 IP 数据库。

License: Apache License 2.0

Python 68.89% Cython 31.11%
python3 cython tornado ip2region ip2location

ip2region's Introduction

查询IP地区工具

     根据IP查询IP地区的工具。使用了Cython优化了性能。结合Tornado可以实现自动更新 IP 数据库。 感谢 ip2region 项目提供的支持。

     由于做项目需要这个工具,也是临时学的Cython,所以欢迎大佬能提出改进意见,继续优化性能。

     有Bug欢迎提 ISSUE ,当然如果能直接提 PullRequest 就更好了。

使用

  • 安装依赖

    pip install -r requirements.txt    
  • 编译 Cython 拓展

    python setup.py build_ext --inplace

    Cython环境的安装请参照官网

  • 测试

    • 简单使用(直接使用自带数据库文件,无自动更新功能,不依赖Tornado

      from searcher import IP2Region
      
      searcher = IP2Region()
      print(searcher.search('8.8.8.8'))

      输出:

      {'city_id': 166, 'region': '美国|0|0|0|Level3'}
    • 基于Tornado实现自动更新数据库文件

      from ip2region_util import IP2RegionUtil
      from tornado.ioloop import IOLoop
      
      util = IP2RegionUtil()
      io_loop = IOLoop.instance()
      print(util.search('8.8.8.8'))
      io_loop.start()

性能

     为了尽量提高性能,本项目在原 ip2region 项目的基础上仅仅保留了内存搜索方法。实际测试比原方法提升一倍以上性能。

     我测试的参考数据:10W/s

数据来源

     数据库文件来自 ip2region,具体数据来源请参考该项目说明。本项目的数据库更新功能严重依赖该项目,该项目停止更新或者数据库文件位置发生变化都会影响数据库更新,请知悉。

     数据库自动更新原理为通过Tornado的定时任务调用GitHubAPI查询数据库文件的SHA信息,如果发生变化则下载新的数据库文件替换。

ip2region's People

Contributors

459217974 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jdk6979 viccom

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.