Giter Club home page Giter Club logo

ip_locator_cn's Introduction

IP Locator CN

Gem Version Build Status Maintainability Test Coverage

基于纯真 IP 库解析**的 IP,参考了“纯真数据库自动更新原理” 和 “PHP 版本的 IP 搜索源码

Installation

Add this line to your application's Gemfile:

gem 'ip_locator_cn'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ip_locator_cn

Usage

从 Gem 包集成的 qqwry.dat 数据库解析 IP:

2.4.5 :001 > require 'ip_locator_cn'
 => true
2.4.5 :002 > IpLocatorCn.resolve('60.195.153.98')
 => {:province=>"北京", :city=>"顺义区", :country=>"**", :ip=>"60.195.153.98", :county=>"", :isp=>"", :area=>"**北京顺义区后沙峪金龙网吧", :origin_country=>"北京市顺义区", :origin_area=>"后沙峪金龙网吧"}

在线下载并解码 qqwry.dat ,然后解析 IP:

2.4.5 :001 > require 'ip_locator_cn'
 => true
2.4.5 :002 > IpLocatorCn.resolve('60.195.153.98', live_dat: true)
 => {:province=>"北京", :city=>"顺义区", :country=>"**", :ip=>"60.195.153.98", :county=>"", :isp=>"", :area=>"**北京顺义区后沙峪金龙网吧", :origin_country=>"北京市顺义区", :origin_area=>"后沙峪金龙网吧"}

开启调试信息:

2.4.5 :001 > require 'ip_locator_cn'
 => true
2.4.5 :002 > IpLocatorCn.resolve('60.195.153.98', live_dat: true, debug: true)
[2019-03-01 17:37:46 +0800] => downloading http://update.cz88.net/ip/copywrite.rar
[2019-03-01 17:37:46 +0800] => downloading http://update.cz88.net/ip/qqwry.rar
[2019-03-01 17:37:49 +0800] => qqwry decoding key is 225
[2019-03-01 17:37:49 +0800] => total ip ranges: 472217
[2019-03-01 17:37:53 +0800] => pos is 6658343
[2019-03-01 17:37:53 +0800] => begin_ip is 60.195.153.0
[2019-03-01 17:37:53 +0800] => endip is 60.195.153.255
[2019-03-01 17:37:53 +0800] => offset is 696416
[2019-03-01 17:37:53 +0800] => country is 北京市顺义区
[2019-03-01 17:37:53 +0800] => area is 后沙峪金龙网吧
 => {:province=>"北京", :city=>"顺义区", :country=>"**", :ip=>"60.195.153.98", :county=>"", :isp=>"", :area=>"**北京顺义区后沙峪金龙网吧", :origin_country=>"北京市顺义区", :origin_area=>"后沙峪金龙网吧"}

TODO

  • Fix: 目前无法提取少数名族地区的城市名称。如:“四川省凉山州西昌市”无法识别出“凉山州”是城市,“西昌市”是县;“内蒙古锡林郭勒盟”,无法识别出“锡林郭勒盟”是城市。
  • 通过 OTA 获取 QQWry 数据后,缓存的到本地磁盘

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/xiaohui-zhangxh/ip_locator_cn.

Test

bundle exec rspec

License

The gem is available as open source under the terms of the MIT License.

ip_locator_cn's People

Contributors

xiaohui-zhangxh avatar

Watchers

James Cloos 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.