Skip to content

A Ruby lib to resolve IP with qqwry.dat, load qqwry.dat on the air.

License

Notifications You must be signed in to change notification settings

xiaohui-zhangxh/ip_locator_cn

Repository files navigation

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.

About

A Ruby lib to resolve IP with qqwry.dat, load qqwry.dat on the air.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published