Coder Social home page Coder Social logo

geoip2pack's Introduction

geoip2pack

对geoip2 的city库进行封装。包括:处理异常以及按**国情修改结果。

处理的异常包括:

  • 有些ip查不到 except geoip2.errors.AddressNotFoundError
  • 有些ip查出来的结果为空 country.name is None
  • 有些国外地址没有省份 subdivisions.most_specific.name is None
  • 有些地址没有中文名 country.names.get('zh-CN',cur_country)
  • 地址中的空格" "和"`"字符处理

**国情修改包括:

  • geoip2将港澳台视为国家一级,将其国家调整为**
  • geoip2将直辖市的区县视为市一级,调整为市

返回信息只包括该ip对应的城市,省份,国家的中文/英文名。

使用说明:

from geoip2pack import GeoIP2Reader

reader = GeoIP2Reader()
ip = '8.8.8.8'
ipinfo = reader.ip2city(ip)
print ip, ipinfo['city'], ipinfo['city_cn'], ipinfo['province'], ipinfo['province_cn'], ipinfo['country'], ipinfo['country_cn'], ipinfo['error']

文件依赖:

  • python 安装 geoip2.database 库
  • 缺省情况下,GeoLite2-City.mmdb 文件应该在执行目录

相关URL:

geoip2pack's People

Contributors

majia29 avatar

Watchers

 avatar  avatar

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.