ip2proxy_ruby 2.0.0 → 2.1.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: 42164edc7ec22e5c5d26f1d6bf3283dda4ab5ecb08dd1e02e4ff9971ec96319a
4
- data.tar.gz: 28340d9b35b272b98f9d8c5a1616e4dfd1d077c57c2e2a25661f94e428631c48
3
+ metadata.gz: 1dc20326c582b22c3ada59ab4987c530b54a4c1693546783fe03ac0afa4d7c3d
4
+ data.tar.gz: e40ee8fc6baec6675fbe8375646d78a3e7d38f0b37f5fb7d8840fbc6b78a7026
5
5
  SHA512:
6
- metadata.gz: 22ee83b9ea0d240269eb1b9f77e0f9f57031ceb7a2a2e59e51d2ea684467eca3317c717df1045e69d70e4affb24d9039ff86631f6294306c2d16254593eaf20e
7
- data.tar.gz: 4fe19be02e16b65d5852b2086c39720de28ddba5ce14a7456bd70a3551c74aaf299c5c8af5775acd02d23dd3fa41b14e112d0f5325eb0c058ebed81e158277c3
6
+ metadata.gz: 947b66ffec9139e7531e9569c9da945b056c842304ab4d866b918995cfb20834d439197d7c7b1119c6a2611fbe2c4fff60ea69126960ef916f1c1e6ea1eb05ce
7
+ data.tar.gz: e182e739e69e2160610b911e67d51997b4a41f58f851d526ea3742b1ddc692aa31cd10790984fad532d0bc92750d7096d2f7aa6201af361e6f7678a39e8e64be
data/example.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'ip2proxy_ruby'
2
2
 
3
3
  # open IP2Proxy BIN database for proxy lookup
4
- i2p = Ip2proxy.new.open("./data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN")
4
+ i2p = Ip2proxy.new.open("./data/IP2PROXY-LITE-PX1.BIN")
5
5
 
6
6
  # get versioning information
7
7
  print 'Module Version: ' + i2p.get_module_version + "\n"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "ip2proxy_ruby"
5
- s.version = "2.0.0"
5
+ s.version = "2.1.0"
6
6
  s.authors = ["ip2location"]
7
7
  s.email = ["support@ip2location.com"]
8
8
 
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  "spec/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN",
35
35
  "spec/ip2proxy_ruby_spec.rb",
36
36
  "spec/spec_helper.rb",
37
- "rb/data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN"
37
+ "rb/data/IP2PROXY-LITE-PX1.BIN"
38
38
  ]
39
39
 
40
40
  if s.respond_to?(:metadata=)
@@ -9,7 +9,7 @@ require_relative 'ip2proxy_ruby/ip2proxy_record'
9
9
  class Ip2proxy
10
10
  attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :record, :database, :columns, :ip_version, :ipv4databasecount, :ipv4databaseaddr, :ipv4indexbaseaddr, :ipv6databasecount, :ipv6databaseaddr, :ipv6indexbaseaddr, :databaseyear, :databasemonth, :databaseday
11
11
 
12
- VERSION = '2.0.0'
12
+ VERSION = '2.1.0'
13
13
  FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
14
14
  INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
15
15
 
@@ -51,23 +51,28 @@ class Ip2proxy
51
51
 
52
52
  def get_record(ip)
53
53
  ipno = IPAddr.new(ip, Socket::AF_UNSPEC)
54
- self.ip_version = ipno.ipv4? ? 4 : 6
55
- self.v4 = ipno.ipv4?
56
- self.count = ipno.ipv4? ? self.ipv4databasecount + 0 : self.ipv6databasecount + 0
57
- self.base_addr = (ipno.ipv4? ? self.ipv4databaseaddr - 1 : self.ipv6databaseaddr - 1)
58
-
59
- ipnum = ipno.to_i + 0
54
+ self.ip_version, ipnum = validateip(ipno)
55
+ self.v4 = ip_version == 4 ? true : false
56
+ self.count = v4 ? self.ipv4databasecount + 0 : self.ipv6databasecount + 0
57
+ self.base_addr = (v4 ? self.ipv4databaseaddr - 1 : self.ipv6databaseaddr - 1)
60
58
  col_length = columns * 4
61
-
62
59
  if ipv4indexbaseaddr > 0 || ipv6indexbaseaddr > 0
63
60
  indexpos = 0
64
61
  case ip_version
65
62
  when 4
66
- ipnum1_2 = (ipnum >> 16)
67
- indexpos = ipv4indexbaseaddr + (ipnum1_2 << 3)
63
+ indexpos = ipv4indexbaseaddr + ((ipnum >> 16) << 3)
64
+ realipno = ipnum
65
+ # if ipnum reach MAX_IPV4_RANGE
66
+ if realipno == 4294967295
67
+ ipnum = realipno - 1
68
+ end
68
69
  when 6
69
- ipnum1 = (ipnum / (2**112))
70
- indexpos = ipv6indexbaseaddr + (ipnum1 << 3)
70
+ indexpos = ipv6indexbaseaddr + ((ipnum >> 112) << 3)
71
+ realipno = ipnum
72
+ # if ipnum reach MAX_IPV6_RANGE
73
+ if realipno == 340282366920938463463374607431768211455
74
+ ipnum = realipno - 1
75
+ end
71
76
  end
72
77
  low = read32(indexpos)
73
78
  high = read32(indexpos + 4)
@@ -277,7 +282,6 @@ class Ip2proxy
277
282
  asn = (defined?(rec.asn) && rec.asn != '') ? rec.asn : FIELD_NOT_SUPPORTED
278
283
  as = (defined?(rec.as) && rec.as != '') ? rec.as : FIELD_NOT_SUPPORTED
279
284
  last_seen = (defined?(rec.lastseen) && rec.lastseen != '') ? rec.lastseen : FIELD_NOT_SUPPORTED
280
-
281
285
  if self.db_index == 1
282
286
  isproxy = (rec.country_short == '-') ? 0 : 1
283
287
  else
@@ -311,7 +315,6 @@ class Ip2proxy
311
315
  last_seen = INVALID_IP_ADDRESS
312
316
  isproxy = -1
313
317
  end
314
-
315
318
  results = {}
316
319
  results['is_proxy'] = isproxy
317
320
  results['proxy_type'] = proxytype
@@ -325,7 +328,6 @@ class Ip2proxy
325
328
  results['asn'] = asn
326
329
  results['as'] = as
327
330
  results['last_seen'] = last_seen
328
-
329
331
  return results
330
332
  end
331
333
 
@@ -348,7 +350,7 @@ class Ip2proxy
348
350
  low = mid + 1
349
351
  end
350
352
  end
351
- end
353
+ end
352
354
  end
353
355
 
354
356
  def get_from_to(mid, base_addr, col_length)
@@ -360,6 +362,38 @@ class Ip2proxy
360
362
  [ip_from, ip_to]
361
363
  end
362
364
 
365
+ def validateip(ip)
366
+ if ip.ipv4?
367
+ ipv = 4
368
+ ipnum = ip.to_i + 0
369
+ else
370
+ ipv = 6
371
+ ipnum = ip.to_i + 0
372
+ #reformat ipv4 address in ipv6
373
+ if ipnum >= 281470681743360 && ipnum <= 281474976710655
374
+ ipv = 4
375
+ ipnum = ipnum - 281470681743360
376
+ end
377
+ #reformat 6to4 address to ipv4 address 2002:: to 2002:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
378
+ if ipnum >= 42545680458834377588178886921629466624 && ipnum <= 42550872755692912415807417417958686719
379
+ ipv = 4
380
+ #bitshift right 80 bits
381
+ ipnum = ipnum >> 80
382
+ #bitwise modulus to get the last 32 bit
383
+ ipnum = ipnum % 4294967296
384
+ end
385
+ #reformat Teredo address to ipv4 address 2001:0000:: to 2001:0000:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:
386
+ if ipnum >= 42540488161975842760550356425300246528 && ipnum <= 42540488241204005274814694018844196863
387
+ ipv = 4
388
+ #bitwise not to invert binary
389
+ ipnum = ~ipnum
390
+ #bitwise modulus to get the last 32 bit
391
+ ipnum = ipnum % 4294967296
392
+ end
393
+ end
394
+ [ipv, ipnum]
395
+ end
396
+
363
397
  def read32(indexp)
364
398
  file.seek(indexp - 1)
365
399
  return file.read(4).unpack('V').first
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ip2proxy_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ip2location
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-13 00:00:00.000000000 Z
11
+ date: 2019-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -120,7 +120,7 @@ files:
120
120
  - lib/ip2proxy_ruby/i2p_string_data.rb
121
121
  - lib/ip2proxy_ruby/ip2proxy_config.rb
122
122
  - lib/ip2proxy_ruby/ip2proxy_record.rb
123
- - rb/data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN
123
+ - rb/data/IP2PROXY-LITE-PX1.BIN
124
124
  - spec/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN
125
125
  - spec/ip2proxy_ruby_spec.rb
126
126
  - spec/spec_helper.rb
@@ -146,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []
149
- rubyforge_project:
150
- rubygems_version: 2.7.6.2
149
+ rubygems_version: 3.0.3
151
150
  signing_key:
152
151
  specification_version: 4
153
152
  summary: IP2Proxy Ruby library