0.0
Low commit activity in last 3 years
No release in over a year
Resolve IP with qqwry.data, can download qqwry.data on the air.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.0
~> 3.0
~> 0.16.1
 Project Readme

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.