ip_locator_cn 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a6d59b99c393a70bc272fb7d6a9af22488f358aff70803fa8edc5ef6a2cd1bc
4
- data.tar.gz: 3f35ee0f891112133baa58a3938e6d2a199296e40bf21c442b34204dd49ecdf2
3
+ metadata.gz: 591a6432b9a000210e613282dfe40749c563d58a1390befad9691edba327b1e8
4
+ data.tar.gz: 18ee39d3f8afd0ff3e1969e8f7ae9553e0a2411ad6322a5738afb4ed421ea2c4
5
5
  SHA512:
6
- metadata.gz: 2bea475014d0f4ad880129b10a8c39dd6e1f930ea4ce92892713bef024160f0ef8ad7804011807bff06b403fbf1dcff27a27b74cd9f471377a0d206002f04fb9
7
- data.tar.gz: d3847a4a344ae42069c5f4a981d21169fdeb231c4b332e606f864efe5b60779c5f76903e7380f1c1605e6524953fe8a346bfaca344f17a95da4ee850456e6a62
6
+ metadata.gz: 58223fcf17a87f4bb5e3803b246da3ec0f357d30ef4064a8820ca5cb9d7c8dee79915cd23af9fbf183efab5ed5f2accb92553bb542ee786231b011e42d0f0354
7
+ data.tar.gz: 9d59a4a5e5241f061ac2134e34b52ba38f8d3990aabca4f39012d508b67812b2e47af2645d445a8f000357ac0988ac1a79e78942b038bf98e52c20b12c8b9c86
data/.gitignore CHANGED
@@ -6,6 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
9
+ /*.gem
10
10
  # rspec failure tracking
11
11
  .rspec_status
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ Style/ExpandPathArguments:
2
+ Enabled: false
3
+ Layout/SpaceAroundEqualsInParameterDefault:
4
+ Enabled: false
data/.travis.yml CHANGED
@@ -4,4 +4,15 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.4.5
7
- before_install: gem install bundler -v 1.16.6
7
+ before_install:
8
+ - gem update --system
9
+ - gem install bundler
10
+ before_script:
11
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
+ - chmod +x ./cc-test-reporter
13
+ - ./cc-test-reporter before-build
14
+ - bundle i
15
+ script:
16
+ - bundle exec rspec
17
+ after_script:
18
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in ip_locator_cn.gemspec
6
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,35 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ip_locator_cn (0.1.0)
4
+ ip_locator_cn (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.3)
9
+ diff-lcs (1.5.0)
10
+ docile (1.4.0)
11
+ json (2.6.3)
10
12
  rake (10.5.0)
11
- rspec (3.8.0)
12
- rspec-core (~> 3.8.0)
13
- rspec-expectations (~> 3.8.0)
14
- rspec-mocks (~> 3.8.0)
15
- rspec-core (3.8.0)
16
- rspec-support (~> 3.8.0)
17
- rspec-expectations (3.8.2)
13
+ rspec (3.12.0)
14
+ rspec-core (~> 3.12.0)
15
+ rspec-expectations (~> 3.12.0)
16
+ rspec-mocks (~> 3.12.0)
17
+ rspec-core (3.12.2)
18
+ rspec-support (~> 3.12.0)
19
+ rspec-expectations (3.12.3)
18
20
  diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.8.0)
20
- rspec-mocks (3.8.0)
21
+ rspec-support (~> 3.12.0)
22
+ rspec-mocks (3.12.5)
21
23
  diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.8.0)
23
- rspec-support (3.8.0)
24
+ rspec-support (~> 3.12.0)
25
+ rspec-support (3.12.0)
26
+ simplecov (0.16.1)
27
+ docile (~> 1.1)
28
+ json (>= 1.8, < 3)
29
+ simplecov-html (~> 0.10.0)
30
+ simplecov-html (0.10.2)
24
31
 
25
32
  PLATFORMS
26
- ruby
33
+ x86_64-darwin-22
27
34
 
28
35
  DEPENDENCIES
29
- bundler (~> 1.16)
30
36
  ip_locator_cn!
31
37
  rake (~> 10.0)
32
38
  rspec (~> 3.0)
39
+ simplecov (~> 0.16.1)
33
40
 
34
41
  BUNDLED WITH
35
- 1.16.6
42
+ 2.4.12
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # IpLocatorCn
1
+ # IP Locator CN
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ip_locator_cn`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem Version](https://badge.fury.io/rb/ip_locator_cn.svg)](https://badge.fury.io/rb/ip_locator_cn) [![Build Status](https://travis-ci.org/xiaohui-zhangxh/ip_locator_cn.svg?branch=master)](https://travis-ci.org/xiaohui-zhangxh/ip_locator_cn) [![Maintainability](https://api.codeclimate.com/v1/badges/ce57ddef67adc3d48378/maintainability)](https://codeclimate.com/github/xiaohui-zhangxh/ip_locator_cn/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/ce57ddef67adc3d48378/test_coverage)](https://codeclimate.com/github/xiaohui-zhangxh/ip_locator_cn/test_coverage) ![](https://ruby-gem-downloads-badge.herokuapp.com/ip_locator_cn?type=total)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ 基于纯真 IP 库解析中国的 IP,参考了“[纯真数据库自动更新原理](https://github.com/shuax/QQWryUpdate/blob/master/update.php)” “[PHP 版本的 IP 搜索源码](https://github.com/itbdw/ip-database/blob/master/src/IpLocation.php)”
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,47 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Gem 包集成的 qqwry.dat 数据库解析 IP:
26
+
27
+ ```ruby
28
+ 2.4.5 :001 > require 'ip_locator_cn'
29
+ => true
30
+ 2.4.5 :002 > IpLocatorCn.resolve('60.195.153.98')
31
+ => {:province=>"北京", :city=>"顺义区", :country=>"中国", :ip=>"60.195.153.98", :county=>"", :isp=>"", :area=>"中国北京顺义区后沙峪金龙网吧", :origin_country=>"北京市顺义区", :origin_area=>"后沙峪金龙网吧"}
32
+ ```
33
+
34
+ 在线下载并解码 qqwry.dat ,然后解析 IP:
35
+
36
+ ```ruby
37
+ 2.4.5 :001 > require 'ip_locator_cn'
38
+ => true
39
+ 2.4.5 :002 > IpLocatorCn.resolve('60.195.153.98', live_dat: true)
40
+ => {:province=>"北京", :city=>"顺义区", :country=>"中国", :ip=>"60.195.153.98", :county=>"", :isp=>"", :area=>"中国北京顺义区后沙峪金龙网吧", :origin_country=>"北京市顺义区", :origin_area=>"后沙峪金龙网吧"}
41
+ ```
42
+
43
+ 开启调试信息:
44
+
45
+ ```ruby
46
+ 2.4.5 :001 > require 'ip_locator_cn'
47
+ => true
48
+ 2.4.5 :002 > IpLocatorCn.resolve('60.195.153.98', live_dat: true, debug: true)
49
+ [2019-03-01 17:37:46 +0800] => downloading http://update.cz88.net/ip/copywrite.rar
50
+ [2019-03-01 17:37:46 +0800] => downloading http://update.cz88.net/ip/qqwry.rar
51
+ [2019-03-01 17:37:49 +0800] => qqwry decoding key is 225
52
+ [2019-03-01 17:37:49 +0800] => total ip ranges: 472217
53
+ [2019-03-01 17:37:53 +0800] => pos is 6658343
54
+ [2019-03-01 17:37:53 +0800] => begin_ip is 60.195.153.0
55
+ [2019-03-01 17:37:53 +0800] => endip is 60.195.153.255
56
+ [2019-03-01 17:37:53 +0800] => offset is 696416
57
+ [2019-03-01 17:37:53 +0800] => country is 北京市顺义区
58
+ [2019-03-01 17:37:53 +0800] => area is 后沙峪金龙网吧
59
+ => {:province=>"北京", :city=>"顺义区", :country=>"中国", :ip=>"60.195.153.98", :county=>"", :isp=>"", :area=>"中国北京顺义区后沙峪金龙网吧", :origin_country=>"北京市顺义区", :origin_area=>"后沙峪金龙网吧"}
60
+ ```
61
+
62
+ ## TODO
63
+
64
+ - [ ] Fix: 目前无法提取少数名族地区的城市名称。如:“四川省凉山州西昌市”无法识别出“凉山州”是城市,“西昌市”是县;“内蒙古锡林郭勒盟”,无法识别出“锡林郭勒盟”是城市。
65
+ - [ ] 通过 OTA 获取 QQWry 数据后,缓存的到本地磁盘
26
66
 
27
67
  ## Development
28
68
 
@@ -34,6 +74,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
34
74
 
35
75
  Bug reports and pull requests are welcome on GitHub at https://github.com/xiaohui-zhangxh/ip_locator_cn.
36
76
 
77
+ ### Test
78
+
79
+ ```bash
80
+ bundle exec rspec
81
+ ```
82
+
37
83
  ## License
38
84
 
39
85
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "ip_locator_cn"
3
+ require 'bundler/setup'
4
+ require 'ip_locator_cn'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "ip_locator_cn"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -1,42 +1,41 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "ip_locator_cn/version"
3
+ require 'ip_locator_cn/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "ip_locator_cn"
6
+ spec.name = 'ip_locator_cn'
8
7
  spec.version = IpLocatorCn::VERSION
9
- spec.authors = ["xiaohui"]
10
- spec.email = ["xiaohui@tanmer.com"]
8
+ spec.authors = ['xiaohui']
9
+ spec.email = ['xiaohui@tanmer.com']
11
10
 
12
- spec.summary = %q{Resolve IP info in China}
13
- spec.description = %q{Resolve IP with qqwry.data, can download qqwry.data on the air.}
14
- spec.homepage = "https://github.com/xiaohui-zhangxh/"
15
- spec.license = "MIT"
11
+ spec.summary = 'Resolve IP info in China'
12
+ spec.description = 'Resolve IP with qqwry.data, can download qqwry.data on the air.'
13
+ spec.homepage = 'https://github.com/xiaohui-zhangxh/ip_locator_cn'
14
+ spec.license = 'MIT'
16
15
 
17
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
18
  if spec.respond_to?(:metadata)
20
19
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
20
 
22
- spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata['homepage_uri'] = spec.homepage
23
22
  # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
23
  # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
24
  else
26
- raise "RubyGems 2.0 or newer is required to protect against " \
27
- "public gem pushes."
25
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
26
+ 'public gem pushes.'
28
27
  end
29
28
 
30
29
  # Specify which files should be added to the gem when it is released.
31
30
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
33
32
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
33
  end
35
- spec.bindir = "exe"
34
+ spec.bindir = 'exe'
36
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
- spec.require_paths = ["lib"]
36
+ spec.require_paths = ['lib']
38
37
 
39
- spec.add_development_dependency "bundler", "~> 1.16"
40
- spec.add_development_dependency "rake", "~> 10.0"
41
- spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'simplecov', '~> 0.16.1'
42
41
  end
@@ -1,10 +1,10 @@
1
1
  module IpLocatorCn
2
2
  class QQWry
3
- CITY_DIRECTLY = [
4
- '北京',
5
- '天津',
6
- '重庆',
7
- '上海',
3
+ CITY_DIRECTLY = %w[
4
+ 北京
5
+ 天津
6
+ 重庆
7
+ 上海
8
8
  ].freeze
9
9
  end
10
10
  end
@@ -1,12 +1,12 @@
1
1
  module IpLocatorCn
2
2
  class QQWry
3
- ISP = [
4
- '联通',
5
- '移动',
6
- '铁通',
7
- '电信',
8
- '长城',
9
- '聚友',
3
+ ISP = %w[
4
+ 联通
5
+ 移动
6
+ 铁通
7
+ 电信
8
+ 长城
9
+ 聚友
10
10
  ].freeze
11
11
  end
12
12
  end
@@ -1,40 +1,40 @@
1
1
  module IpLocatorCn
2
2
  class QQWry
3
- PROVINCES = [
4
- '北京',
5
- '天津',
6
- '重庆',
7
- '上海',
8
- '河北',
9
- '山西',
10
- '辽宁',
11
- '吉林',
12
- '黑龙江',
13
- '江苏',
14
- '浙江',
15
- '安徽',
16
- '福建',
17
- '江西',
18
- '山东',
19
- '河南',
20
- '湖北',
21
- '湖南',
22
- '广东',
23
- '海南',
24
- '四川',
25
- '贵州',
26
- '云南',
27
- '陕西',
28
- '甘肃',
29
- '青海',
30
- '台湾',
31
- '内蒙古',
32
- '广西',
33
- '宁夏',
34
- '新疆',
35
- '西藏',
36
- '香港',
37
- '澳门',
3
+ PROVINCES = %w[
4
+ 北京
5
+ 天津
6
+ 重庆
7
+ 上海
8
+ 河北
9
+ 山西
10
+ 辽宁
11
+ 吉林
12
+ 黑龙江
13
+ 江苏
14
+ 浙江
15
+ 安徽
16
+ 福建
17
+ 江西
18
+ 山东
19
+ 河南
20
+ 湖北
21
+ 湖南
22
+ 广东
23
+ 海南
24
+ 四川
25
+ 贵州
26
+ 云南
27
+ 陕西
28
+ 甘肃
29
+ 青海
30
+ 台湾
31
+ 内蒙古
32
+ 广西
33
+ 宁夏
34
+ 新疆
35
+ 西藏
36
+ 香港
37
+ 澳门
38
38
  ].freeze
39
39
  end
40
40
  end
@@ -4,7 +4,7 @@ require 'ip_locator_cn/qqwry/isp'
4
4
 
5
5
  module IpLocatorCn
6
6
  class QQWry
7
- IP_ENTRY_BYTES = 7.freeze
7
+ IP_ENTRY_BYTES = 7
8
8
 
9
9
  attr_reader :first_ip_pos, :last_ip_pos, :total_ips, :debug
10
10
 
@@ -20,13 +20,15 @@ module IpLocatorCn
20
20
  end
21
21
 
22
22
  # return: <Hash> result
23
- # result['ip'] 输入的ip
24
- # result['country'] 国家 如 中国
25
- # result['province'] 省份信息 如 河北省
26
- # result['city'] 市区 如 邢台市
27
- # result['county'] 郡县 如 威县
28
- # result['isp'] 运营商 如 联通
29
- # result['area'] 最完整的信息 如 中国河北省邢台市威县新科网吧(北外街)
23
+ # result['ip'] 输入的ip
24
+ # result['country'] 国家 如 中国
25
+ # result['province'] 省份信息 如 河北省
26
+ # result['city'] 市区 如 邢台市
27
+ # result['county'] 郡县 如 威县
28
+ # result['isp'] 运营商 如 联通
29
+ # result['area'] 最完整的信息 如 中国河北省邢台市威县新科网吧(北外街)
30
+ # result['origin_country'] 解析之前的原始信息
31
+ # result['origin_area'] 解析之前的原始信息
30
32
  def resolve(ip)
31
33
  location = location_from_ip(ip)
32
34
  extract_location(location[:country]).tap do |result|
@@ -43,6 +45,8 @@ module IpLocatorCn
43
45
  result[:county],
44
46
  location[:area]
45
47
  ].join
48
+ result[:origin_country] = location[:country]
49
+ result[:origin_area] = location[:area]
46
50
  end
47
51
  end
48
52
 
@@ -52,40 +56,40 @@ module IpLocatorCn
52
56
  log "pos is #{pos}"
53
57
  # 用户IP所在范围的开始地址
54
58
  seek(pos)
55
- begin_ip = long2ip(read_ip())
59
+ begin_ip = long2ip(read_ip)
56
60
  log "begin_ip is #{begin_ip}"
57
61
  # 用户IP所在范围的结束地址
58
- offset = getlong3()
62
+ offset = getlong3
59
63
  seek(offset)
60
- endip = long2ip(read_ip())
64
+ endip = long2ip(read_ip)
61
65
  log "endip is #{endip}"
62
66
  log "offset is #{offset}"
63
67
  byte = read(1) # 标志字节
64
68
  case byte.ord
65
69
  when 1
66
70
  # 标志字节为1,表示国家和区域信息都被同时重定向
67
- country_offset = getlong3() # 重定向地址
71
+ country_offset = getlong3 # 重定向地址
68
72
  seek(country_offset)
69
73
  byte = read(1) # 标志字节
70
74
  case byte.ord
71
75
  when 2
72
76
  seek(getlong3)
73
- info[:country] = getstring()
77
+ info[:country] = getstring
74
78
  seek(country_offset + 4)
75
- info[:area] = getarea()
79
+ info[:area] = getarea
76
80
  else
77
81
  info[:country] = getstring(byte)
78
- info[:area] = getarea()
82
+ info[:area] = getarea
79
83
  end
80
84
  when 2
81
85
  # 标志字节为2,表示国家信息被重定向
82
86
  seek(getlong3)
83
- info[:country] = getstring()
87
+ info[:country] = getstring
84
88
  seek(offset + 8)
85
- info[:area] = getarea()
89
+ info[:area] = getarea
86
90
  else
87
91
  info[:country] = getstring(byte)
88
- info[:area] = getarea()
92
+ info[:area] = getarea
89
93
  end
90
94
 
91
95
  info[:country] = encoding_convert(info[:country])
@@ -116,8 +120,8 @@ module IpLocatorCn
116
120
  if str.include?(seperator_sheng)
117
121
  collection[:province], str = str.split(seperator_sheng, 2)
118
122
  else
119
- province = (PROVINCES + CITY_DIRECTLY).find{ |x| str.start_with?(x) }
120
- if x
123
+ province = (PROVINCES + CITY_DIRECTLY).find { |x| str.start_with?(x) }
124
+ if province
121
125
  collection[:province] = province
122
126
  is_city_directly = CITY_DIRECTLY.include?(province)
123
127
  str = str[province.length..-1]
@@ -162,8 +166,8 @@ module IpLocatorCn
162
166
 
163
167
  def live_load_dat
164
168
  require 'open-uri'
165
- copywrite = download(IpLocatorCn.copywrite_url).read and nil
166
- qqwry = download(IpLocatorCn.live_data_url).read.bytes and nil
169
+ (copywrite = download(IpLocatorCn.copywrite_url).read) && nil
170
+ (qqwry = download(IpLocatorCn.live_data_url).read.bytes) && nil
167
171
  key = copywrite.unpack('V6')[5]
168
172
  log "qqwry decoding key is #{key}"
169
173
  (0...0x200).each do |i|
@@ -172,25 +176,26 @@ module IpLocatorCn
172
176
  key &= 0xFF
173
177
  qqwry[i] ^= key
174
178
  end
175
- qqwry = Zlib::Inflate.inflate(qqwry.pack('C*')) and nil
179
+ (qqwry = Zlib::Inflate.inflate(qqwry.pack('C*'))) && nil
176
180
  @io = StringIO.new(qqwry)
177
181
  end
178
182
 
179
183
  def parse_dat_info
180
- @first_ip_pos = getlong4()
181
- @last_ip_pos = getlong4()
184
+ @first_ip_pos = getlong4
185
+ @last_ip_pos = getlong4
182
186
  @total_ips = (last_ip_pos - first_ip_pos) / IP_ENTRY_BYTES
183
187
  log "total ip ranges: #{total_ips}"
184
188
  end
185
189
 
186
190
  def get_isp(str)
187
- ISP.find {|x| str.include?(x)}
191
+ ISP.find { |x| str.include?(x) }
188
192
  end
189
193
 
190
194
  # b-tree search ip from qqwry.dat
191
195
  def locate_ip_pos(ip)
192
196
  x = ip2long(ip)
193
- min, max = 0, total_ips
197
+ min = 0
198
+ max = total_ips
194
199
 
195
200
  while min <= max
196
201
  # b-tree search
@@ -198,14 +203,14 @@ module IpLocatorCn
198
203
  pos = first_ip_pos + i * IP_ENTRY_BYTES
199
204
  seek(pos)
200
205
  # get middle ip
201
- y = read_ip()
206
+ y = read_ip
202
207
  if x < y
203
208
  # user ip < middle ip
204
209
  max = i - 1
205
210
  else
206
211
  # user ip > middle ip, read next ip entry
207
212
  read(3)
208
- y = read_ip()
213
+ y = read_ip
209
214
  if x > y
210
215
  # user ip > next ip
211
216
  min = i + 1
@@ -243,14 +248,14 @@ module IpLocatorCn
243
248
  end
244
249
 
245
250
  def ipparts2long(parts)
246
- 0.upto(3).map{|i| parts[i] << ((3 - i) * 8) }.sum
251
+ 0.upto(3).map { |i| parts[i] << ((3 - i) * 8) }.sum
247
252
  end
248
253
 
249
254
  def long2ip(n)
250
- 0.upto(3).map{|i| (n >> ((3 - i) * 8)) & 0xFF }.join('.')
255
+ 0.upto(3).map { |i| (n >> ((3 - i) * 8)) & 0xFF }.join('.')
251
256
  end
252
257
 
253
- def getstring(data='')
258
+ def getstring(data = '')
254
259
  char = read(1)
255
260
  while char.ord > 0
256
261
  data += char
@@ -267,14 +272,14 @@ module IpLocatorCn
267
272
  return ''
268
273
  when 1, 2
269
274
  seek(getlong3)
270
- return getstring()
275
+ return getstring
271
276
  else
272
277
  return getstring(char)
273
278
  end
274
279
  end
275
280
 
276
281
  def encoding_convert(str)
277
- ec = Encoding::Converter.new("GBK", "UTF-8")
282
+ ec = Encoding::Converter.new('GBK', 'UTF-8')
278
283
  result = ec.convert(str)
279
284
  ec.finish
280
285
  result
@@ -1,3 +1,3 @@
1
1
  module IpLocatorCn
2
- VERSION = "0.1.0"
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/ip_locator_cn.rb CHANGED
@@ -1,5 +1,6 @@
1
- require "ip_locator_cn/version"
1
+ require 'ip_locator_cn/version'
2
2
  require 'ip_locator_cn/qqwry'
3
+
3
4
  module IpLocatorCn
4
5
  # embeded qqwry.dat
5
6
  def self.data_path
@@ -15,7 +16,7 @@ module IpLocatorCn
15
16
  'http://update.cz88.net/ip/copywrite.rar'
16
17
  end
17
18
 
18
- def self.resolve(ip)
19
- QQWry.new(dat_path: data_path).resolve(ip)
19
+ def self.resolve(ip, options={ dat_path: data_path })
20
+ QQWry.new(**options).resolve(ip)
20
21
  end
21
22
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ip_locator_cn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xiaohui
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-28 00:00:00.000000000 Z
11
+ date: 2023-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '10.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '10.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '3.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: simplecov
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: 0.16.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
54
+ version: 0.16.1
55
55
  description: Resolve IP with qqwry.data, can download qqwry.data on the air.
56
56
  email:
57
57
  - xiaohui@tanmer.com
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
+ - ".rubocop.yml"
64
65
  - ".travis.yml"
65
66
  - Gemfile
66
67
  - Gemfile.lock
@@ -77,12 +78,12 @@ files:
77
78
  - lib/ip_locator_cn/qqwry/isp.rb
78
79
  - lib/ip_locator_cn/qqwry/provinces.rb
79
80
  - lib/ip_locator_cn/version.rb
80
- homepage: https://github.com/xiaohui-zhangxh/
81
+ homepage: https://github.com/xiaohui-zhangxh/ip_locator_cn
81
82
  licenses:
82
83
  - MIT
83
84
  metadata:
84
- homepage_uri: https://github.com/xiaohui-zhangxh/
85
- post_install_message:
85
+ homepage_uri: https://github.com/xiaohui-zhangxh/ip_locator_cn
86
+ post_install_message:
86
87
  rdoc_options: []
87
88
  require_paths:
88
89
  - lib
@@ -97,9 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  - !ruby/object:Gem::Version
98
99
  version: '0'
99
100
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.7.8
102
- signing_key:
101
+ rubygems_version: 3.4.12
102
+ signing_key:
103
103
  specification_version: 4
104
104
  summary: Resolve IP info in China
105
105
  test_files: []