ip2location_ruby 8.3.2 → 8.4.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: f65c7c4cdd394a27ed94056f2b040291f5728c074cac760222a323746821d050
4
- data.tar.gz: 73afe05c310a00fe285c5c92b7c8d305ca7d360f223731ae52a1fc26f40ce308
3
+ metadata.gz: c6b5f833dfd8e52321b11114f24103b44ff2cc9279360a71a0948ecb6742d2d1
4
+ data.tar.gz: 9f2b62167a00f19ac4f342d222291c108a3204b4c99324e9c21770339a73444d
5
5
  SHA512:
6
- metadata.gz: b3a4ef0bbefe2bdd34ec42da052dd0358e45165432ef46bf988649931c78df4e6b37c985f916b3905025a1c51f53050b57e457cbaab476a68af51bde6ba89b53
7
- data.tar.gz: 55926d42c6326264454762933b14b43036d3d9834641e88dd1d27f924b02e462eed2f206706b8e359a8c01ac1351f135a2b7096c249c48a90ac31532988604ee
6
+ metadata.gz: 59be638fbbba78173c4fc3ba9bc708d4a43b21024cf5e675135533bbc10093c6a6707a15e108646e0d546b130e59a63e355c9d2c2ace995b0bd59c51484c454d
7
+ data.tar.gz: 283ac65d80c92f7bd054eb82399217901b08da84b965fa6764002baa5773073f130689b0646217b98ff62ebacf672e6990787a5d287075750eb05b9518f3892f
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021 IP2Location ( support@ip2location.com )
1
+ Copyright (c) 2022 IP2Location ( support@ip2location.com )
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -56,7 +56,6 @@ Below is the description of the functions available in the **BIN Database** look
56
56
  | get_addresstype | Returns the IP address type (A-Anycast, B-Broadcast, M-Multicast & U-Unicast) of IP address or domain name. |
57
57
  | get_category | Returns the IAB content taxonomy category of IP address or domain name. |
58
58
 
59
-
60
59
  ## Web Service
61
60
  Below is the description of the functions available in the **Web Service** lookup.
62
61
 
@@ -66,6 +65,24 @@ Below is the description of the functions available in the **Web Service** looku
66
65
  | lookup | Return the IP information in array.<ul><li>country_code</li><li>country_name</li><li>region_name</li><li>city_name</li><li>latitude</li><li>longitude</li><li>zip_code</li><li>time_zone</li><li>isp</li><li>domain</li><li>net_speed</li><li>idd_code</li><li>area_code</li><li>weather_station_code</li><li>weather_station_name</li><li>mcc</li><li>mnc</li><li>mobile_brand</li><li>elevation</li><li>usage_type</li><li>address_type</li><li>category</li><li>continent<ul><li>name</li><li>code</li><li>hemisphere</li><li>translations</li></ul></li><li>country<ul><li>name</li><li>alpha3_code</li><li>numeric_code</li><li>demonym</li><li>flag</li><li>capital</li><li>total_area</li><li>population</li><li>currency<ul><li>code</li><li>name</li><li>symbol</li></ul></li><li>language<ul><li>code</li><li>name</li></ul></li><li>idd_code</li><li>tld</li><li>translations</li></ul></li><li>region<ul><li>name</li><li>code</li><li>translations</li></ul></li><li>city<ul><li>name</li><li>translations</li></ul></li><li>geotargeting<ul><li>metro</li></ul></li><li>country_groupings</li><li>time_zone_info<ul><li>olson</li><li>current_time</li><li>gmt_offset</li><li>is_dst</li><li>sunrise</li><li>sunset</li></ul></li><ul> |
67
66
  | get_credit | Return remaining credit of the web service account. |
68
67
 
68
+ ## IpTools
69
+ Below is the description of the functions available in the **IpTools** class.
70
+
71
+ | Function Name | Description |
72
+ |---|---|
73
+ | is_ipv4 | Return either true or false. Verify if a string is a valid IPv4 address. |
74
+ | is_ipv6 | Return either true or false. Verify if a string is a valid IPv6 address. |
75
+ | ipv4_to_decimal | Translate IPv4 address from dotted-decimal address to decimal format. Return null on error. |
76
+ | decimal_to_ipv4 | Translate IPv4 address from decimal number to dotted-decimal address. Return null on error. |
77
+ | ipv6_to_decimal | Translate IPv6 address from hexadecimal address to decimal format. Return null on error. |
78
+ | decimal_to_ipv6 | Translate IPv6 address from decimal number into hexadecimal address. Return null on error. |
79
+ | ipv4_to_cidr | Convert IPv4 range into a list of IPv4 CIDR notation. |
80
+ | cidr_to_ipv4 | Convert IPv4 CIDR notation into a list of IPv4 addresses. |
81
+ | ipv6_to_cidr | Convert IPv6 range into a list of IPv6 CIDR notation. |
82
+ | cidr_to_ipv6 | Convert IPv6 CIDR notation into a list of IPv6 addresses. |
83
+ | compress_ipv6 | Compress a IPv6 to shorten the length. |
84
+ | expand_ipv6 | Expand a shorten IPv6 to full length. |
85
+
69
86
  # Dependencies
70
87
  This library requires IP2Location BIN data file to function. You may download the BIN data file at
71
88
  * IP2Location LITE BIN Data (Free): https://lite.ip2location.com
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.3.2
1
+ 8.4.0
data/example.rb CHANGED
@@ -4,40 +4,51 @@ require 'ip2location_ruby'
4
4
  i2l = Ip2location.new.open("./data/IP2LOCATION-LITE-DB1.IPV6.BIN")
5
5
  record = i2l.get_all('8.8.8.8')
6
6
 
7
- print 'Country Code: ' + record['country_short'] + "\n"
8
- print 'Country Name: ' + record['country_long'] + "\n"
9
- print 'Region Name: ' + record['region'] + "\n"
10
- print 'City Name: ' + record['city'] + "\n"
11
- print 'Latitude: '
12
- print record['latitude']
13
- print "\n"
14
- print 'Longitude: '
15
- print record['longitude']
16
- print "\n"
17
- print 'ISP: ' + record['isp'] + "\n"
18
- print 'Domain: ' + record['domain'] + "\n"
19
- print 'Net Speed: ' + record['netspeed'] + "\n"
20
- print 'Area Code: ' + record['areacode'] + "\n"
21
- print 'IDD Code: ' + record['iddcode'] + "\n"
22
- print 'Time Zone: ' + record['timezone'] + "\n"
23
- print 'ZIP Code: ' + record['zipcode'] + "\n"
24
- print 'Weather Station Code: ' + record['weatherstationname'] + "\n"
25
- print 'Weather Station Name: ' + record['weatherstationcode'] + "\n"
26
- print 'MCC: ' + record['mcc'] + "\n"
27
- print 'MNC: ' + record['mnc'] + "\n"
28
- print 'Mobile Name: ' + record['mobilebrand'] + "\n"
29
- print 'Elevation: '
30
- print record['elevation']
31
- print "\n"
32
- print 'Usage Type: ' + record['usagetype'] + "\n"
33
- print 'Address Type: ' + record['addresstype'] + "\n"
34
- print 'Category: ' + record['category'] + "\n"
7
+ puts 'Country Code: ' + record['country_short']
8
+ puts 'Country Name: ' + record['country_long']
9
+ puts 'Region Name: ' + record['region']
10
+ puts 'City Name: ' + record['city']
11
+ puts 'Latitude: '
12
+ puts record['latitude']
13
+ puts 'Longitude: '
14
+ puts record['longitude']
15
+ puts 'ISP: ' + record['isp']
16
+ puts 'Domain: ' + record['domain']
17
+ puts 'Net Speed: ' + record['netspeed']
18
+ puts 'Area Code: ' + record['areacode']
19
+ puts 'IDD Code: ' + record['iddcode']
20
+ puts 'Time Zone: ' + record['timezone']
21
+ puts 'ZIP Code: ' + record['zipcode']
22
+ puts 'Weather Station Code: ' + record['weatherstationname']
23
+ puts 'Weather Station Name: ' + record['weatherstationcode']
24
+ puts 'MCC: ' + record['mcc']
25
+ puts 'MNC: ' + record['mnc']
26
+ puts 'Mobile Name: ' + record['mobilebrand']
27
+ puts 'Elevation: '
28
+ puts record['elevation']
29
+ puts 'Usage Type: ' + record['usagetype']
30
+ puts 'Address Type: ' + record['addresstype']
31
+ puts 'Category: ' + record['category']
35
32
 
36
33
  i2l.close()
37
34
 
38
35
  # Web Service
39
36
  ws = Ip2locationWebService.new('demo', 'WS25', true)
40
37
  record = ws.lookup('8.8.8.8', 'continent,country,region,city,geotargeting,country_groupings,time_zone_info', 'en')
41
- print record
42
- print "\n"
43
- print ws.get_credit()
38
+ puts record
39
+ puts ws.get_credit()
40
+
41
+ # IP Tools
42
+ iptool = Ip2locationIpTools.new()
43
+ puts iptool.is_ipv4('8.8.8.8')
44
+ puts iptool.is_ipv6('2001:4860:4860::8888')
45
+ puts iptool.ipv4_to_decimal('8.8.8.8')
46
+ puts iptool.decimal_to_ipv4(134744072)
47
+ puts iptool.ipv6_to_decimal('2001:4860:4860::8888')
48
+ puts iptool.decimal_to_ipv6(42541956123769884636017138956568135816)
49
+ puts iptool.ipv4_to_cidr('8.0.0.0', '8.255.255.255')
50
+ puts iptool.cidr_to_ipv4('8.0.0.0/8')
51
+ puts iptool.ipv6_to_cidr('2002:0000:0000:1234:abcd:ffff:c0a8:0000', '2002:0000:0000:1234:ffff:ffff:ffff:ffff')
52
+ puts iptool.cidr_to_ipv6('2002::1234:abcd:ffff:c0a8:101/64')
53
+ puts iptool.compress_ipv6('2002:0000:0000:1234:ffff:ffff:ffff:ffff')
54
+ puts iptool.expand_ipv6('2002::1234:ffff:ffff:ffff:ffff')
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ip2location_ruby"
3
- s.version = "8.3.2"
3
+ s.version = "8.4.0"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.require_paths = ["lib"]
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/ip2location_ruby/ip2location_record.rb",
32
32
  "spec/assets/IP2LOCATION-LITE-DB1.IPV6.BIN",
33
33
  "spec/ip2location_ruby_database_spec.rb",
34
+ "spec/ip2location_ruby_iptools_spec.rb",
34
35
  "spec/ip2location_ruby_webservice_spec.rb",
35
36
  "spec/spec_helper.rb",
36
37
  "rb/data/IP2LOCATION-LITE-DB1.IPV6.BIN"
@@ -13,7 +13,7 @@ require 'ip2location_ruby/ip2location_record'
13
13
  class Ip2location
14
14
  attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :count, :record, :database, :columns, :ip_version, :ipv4databasecount, :ipv4databaseaddr, :ipv4indexbaseaddr, :ipv6databasecount, :ipv6databaseaddr, :ipv6indexbaseaddr, :databaseyear, :databasemonth, :databaseday, :last_err_msg
15
15
 
16
- VERSION = '8.3.2'
16
+ VERSION = '8.4.0'
17
17
  FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
18
18
  INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
19
19
  INVALID_BIN_DATABASE = 'Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file.'
@@ -651,7 +651,7 @@ class Ip2location
651
651
  else
652
652
  ipv = 6
653
653
  ipnum = ip.to_i + 0
654
- #reformat ipv4 address in ipv6
654
+ #reformat ipv4 address in ipv6
655
655
  if ipnum >= 281470681743360 && ipnum <= 281474976710655
656
656
  ipv = 4
657
657
  ipnum = ipnum - 281470681743360
@@ -717,7 +717,7 @@ class Ip2locationWebService
717
717
  if parsed_response.nil?
718
718
  return false
719
719
  end
720
- if !parsed_response["response"].nil?
720
+ if parsed_response["country_code"].nil?
721
721
  raise Exception.new "Error: " + parsed_response["response"]
722
722
  end
723
723
  return parsed_response
@@ -738,4 +738,228 @@ class Ip2locationWebService
738
738
  end
739
739
  return parsed_response["response"]
740
740
  end
741
+ end
742
+
743
+ class Ip2locationIpTools
744
+ def is_ipv4(ip)
745
+ if !(IPAddr.new(ip) rescue nil).nil?
746
+ if IPAddr.new(ip).ipv4?
747
+ return true
748
+ else
749
+ return false
750
+ end
751
+ else
752
+ return false
753
+ end
754
+ end
755
+
756
+ def is_ipv6(ip)
757
+ if !(IPAddr.new(ip) rescue nil).nil?
758
+ if IPAddr.new(ip).ipv6?
759
+ return true
760
+ else
761
+ return false
762
+ end
763
+ else
764
+ return false
765
+ end
766
+ end
767
+
768
+ def ipv4_to_decimal(ip)
769
+ if !(IPAddr.new(ip) rescue nil).nil?
770
+ ip = IPAddr.new(ip)
771
+ if ip.ipv4?
772
+ return ip.to_i
773
+ else
774
+ return
775
+ end
776
+ else
777
+ return
778
+ end
779
+ end
780
+
781
+ def decimal_to_ipv4(number)
782
+ if number.is_a? Numeric
783
+ return IPAddr.new(number, Socket::AF_INET).to_s
784
+ else
785
+ return
786
+ end
787
+ end
788
+
789
+ def ipv6_to_decimal(ip)
790
+ if !(IPAddr.new(ip) rescue nil).nil?
791
+ ip = IPAddr.new(ip)
792
+ if ip.ipv6?
793
+ return ip.to_i
794
+ else
795
+ return
796
+ end
797
+ else
798
+ return
799
+ end
800
+ end
801
+
802
+ def decimal_to_ipv6(number)
803
+ if number.is_a? Numeric
804
+ return IPAddr.new(number, Socket::AF_INET6).to_s
805
+ else
806
+ return
807
+ end
808
+ end
809
+
810
+ def ipv4_to_cidr(ipfrom, ipto)
811
+ if (!(IPAddr.new(ipfrom) rescue nil).nil?) and (!(IPAddr.new(ipto) rescue nil).nil?)
812
+ ipfrom = IPAddr.new(ipfrom)
813
+ ipto = IPAddr.new(ipto)
814
+ if ipfrom.ipv4? and ipto.ipv4?
815
+ ipfrom = ipfrom.to_i
816
+ ipto = ipto.to_i
817
+ result = []
818
+ while ipto >= ipfrom do
819
+ maxSize = 32
820
+ while maxSize > 0 do
821
+ mask = (2**32 - 2**(32-(maxSize - 1)))
822
+ maskBase = ipfrom & mask
823
+ if maskBase != ipfrom
824
+ break
825
+ end
826
+ maxSize-=1
827
+ end
828
+ x = Math.log(ipto - ipfrom + 1)/Math.log(2)
829
+ maxDiff = (32 - x.floor).floor
830
+
831
+ if maxSize < maxDiff
832
+ maxSize = maxDiff
833
+ end
834
+
835
+ ip = IPAddr.new(ipfrom, Socket::AF_INET).to_s
836
+ cidr = [ip, maxSize].join('/')
837
+ result.push cidr
838
+ ipfrom += 2**(32-maxSize)
839
+ end
840
+ return result
841
+ else
842
+ return
843
+ end
844
+ else
845
+ return
846
+ end
847
+ end
848
+
849
+ def cidr_to_ipv4(cidr)
850
+ if cidr.include? "/"
851
+ cidr = IPAddr.new(cidr)
852
+ arr_tmp = cidr.to_range.to_s.split('..')
853
+ ip_arr = {}
854
+ ip_arr['ip_start'] = arr_tmp[0]
855
+ ip_arr['ip_end'] = arr_tmp[1]
856
+ return ip_arr
857
+ else
858
+ return
859
+ end
860
+ end
861
+
862
+ def ipv6_to_cidr(ipfrom_ori, ipto)
863
+ if (!(IPAddr.new(ipfrom_ori) rescue nil).nil?) and (!(IPAddr.new(ipto) rescue nil).nil?)
864
+ ipfrom = IPAddr.new(ipfrom_ori)
865
+ ipto = IPAddr.new(ipto)
866
+ if ipfrom.ipv6? and ipto.ipv6?
867
+ ipfrom = '00' + ipfrom.to_i.to_s(2)
868
+ ipto = '00' + ipto.to_i.to_s(2)
869
+ result = []
870
+ if ipfrom == ipto
871
+ cidr = ipfrom_ori + '/128'
872
+ result.push cidr
873
+ return result
874
+ end
875
+ if ipfrom > ipto
876
+ ipfrom, ipto = ipto, ipfrom
877
+ end
878
+ networks = {}
879
+ network_size = 0
880
+ while ipto > ipfrom do
881
+ if ipfrom[-1, 1] == '1'
882
+ networks[ipfrom[network_size, (128 - network_size)] + ('0' * network_size)] = 128 - network_size
883
+ n = ipfrom.rindex('0')
884
+ ipfrom = ((n == 0) ? '' : ipfrom[0, n]) + '1' + ('0' * (128 - n - 1))
885
+ end
886
+
887
+ if ipto[-1, 1] == '0'
888
+ networks[ipto[network_size, (128 - network_size)] + ('0' * network_size)] = 128 - network_size
889
+ n = ipto.rindex('1')
890
+ ipto = ((n == 0) ? '' : ipto[0, n]) + '0' + ('1' * (128 - n - 1))
891
+ end
892
+
893
+ if ipfrom > ipto
894
+ next
895
+ end
896
+
897
+ shift = 128 - [ipfrom.rindex('0'), ipto.rindex('1')].max
898
+ ipfrom = ('0' * shift) + ipfrom[0, (128 - shift)]
899
+ ipto = ('0' * shift) + ipto[0, (128 - shift)]
900
+ network_size = network_size + shift
901
+
902
+ if ipfrom == ipto
903
+ networks[ipfrom[network_size, (128 - network_size)] + ('0' * network_size)] = 128 - network_size
904
+ next
905
+ end
906
+ end
907
+
908
+ networks.each do |ip, netmask|
909
+ result.push IPAddr.new(ip.to_i(2), Socket::AF_INET6).to_s + '/' + netmask.to_s
910
+ end
911
+ return result
912
+ else
913
+ return
914
+ end
915
+ else
916
+ return
917
+ end
918
+ end
919
+
920
+ def cidr_to_ipv6(cidr)
921
+ if cidr.include? "/"
922
+ ip_start = IPAddr.new(cidr.to_s.split('/').first).to_i.to_s(16).scan(/.{4}/)
923
+ ip_start = ip_start[0] + ':' + ip_start[1] + ':' + ip_start[2] + ':' + ip_start[3] + ':' + ip_start[4] + ':' + ip_start[5] + ':' + ip_start[6] + ':' + ip_start[7]
924
+
925
+ cidr_new = IPAddr.new(cidr)
926
+ arr_tmp = cidr_new.to_range.to_s.split('..')
927
+ ip_end = IPAddr.new(arr_tmp[1]).to_i.to_s(16).scan(/.{4}/)
928
+ ip_end = ip_end[0] + ':' + ip_end[1] + ':' + ip_end[2] + ':' + ip_end[3] + ':' + ip_end[4] + ':' + ip_end[5] + ':' + ip_end[6] + ':' + ip_end[7]
929
+
930
+ ip_arr = {}
931
+ ip_arr['ip_start'] = ip_start
932
+ ip_arr['ip_end'] = ip_end
933
+ return ip_arr
934
+ else
935
+ return
936
+ end
937
+ end
938
+
939
+ def compress_ipv6(ip)
940
+ if !(IPAddr.new(ip) rescue nil).nil?
941
+ ip = IPAddr.new(ip)
942
+ if ip.ipv6?
943
+ return ip
944
+ else
945
+ return
946
+ end
947
+ else
948
+ return
949
+ end
950
+ end
951
+
952
+ def expand_ipv6(ip)
953
+ if !(IPAddr.new(ip) rescue nil).nil?
954
+ ip = IPAddr.new(ip)
955
+ if ip.ipv6?
956
+ res = ip.to_i.to_s(16).scan(/.{4}/)
957
+ return res[0] + ':' + res[1] + ':' + res[2] + ':' + res[3] + ':' + res[4] + ':' + res[5] + ':' + res[6] + ':' + res[7]
958
+ else
959
+ return
960
+ end
961
+ else
962
+ return
963
+ end
964
+ end
741
965
  end
@@ -0,0 +1,94 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Ip2location" do
4
+ it "work correctly with iptools is_ipv4" do
5
+ iptool = Ip2locationIpTools.new()
6
+ record = iptool.is_ipv4('8.8.8.8')
7
+ expect(record).to eq true
8
+ end
9
+
10
+ it "work correctly with iptools invalid is_ipv4" do
11
+ iptool = Ip2locationIpTools.new()
12
+ record = iptool.is_ipv4('8.8.8.555')
13
+ expect(record).to eq false
14
+ end
15
+
16
+ it "work correctly with iptools is_ipv6" do
17
+ iptool = Ip2locationIpTools.new()
18
+ record = iptool.is_ipv6('2001:4860:4860::8888')
19
+ expect(record).to eq true
20
+ end
21
+
22
+ it "work correctly with iptools invalid is_ipv6" do
23
+ iptool = Ip2locationIpTools.new()
24
+ record = iptool.is_ipv6('2001:4860:4860::ZZZZ')
25
+ expect(record).to eq false
26
+ end
27
+
28
+ it "work correctly with iptools ipv4_to_decimal" do
29
+ iptool = Ip2locationIpTools.new()
30
+ record = iptool.ipv4_to_decimal('8.8.8.8')
31
+ expect(record).to eq 134744072
32
+ end
33
+
34
+ it "work correctly with iptools decimal_to_ipv4" do
35
+ iptool = Ip2locationIpTools.new()
36
+ record = iptool.decimal_to_ipv4(134744072)
37
+ expect(record).to eq '8.8.8.8'
38
+ end
39
+
40
+ it "work correctly with iptools ipv6_to_decimal" do
41
+ iptool = Ip2locationIpTools.new()
42
+ record = iptool.ipv6_to_decimal('2001:4860:4860::8888')
43
+ expect(record).to eq 42541956123769884636017138956568135816
44
+ end
45
+
46
+ it "work correctly with iptools decimal_to_ipv6" do
47
+ iptool = Ip2locationIpTools.new()
48
+ record = iptool.decimal_to_ipv6(42541956123769884636017138956568135816)
49
+ expect(record).to eq '2001:4860:4860::8888'
50
+ end
51
+
52
+ it "work correctly with iptools ipv4_to_cidr" do
53
+ iptool = Ip2locationIpTools.new()
54
+ record = iptool.ipv4_to_cidr('8.0.0.0', '8.255.255.255')
55
+ expect(record).to eq ['8.0.0.0/8']
56
+ end
57
+
58
+ it "work correctly with iptools cidr_to_ipv4" do
59
+ iptool = Ip2locationIpTools.new()
60
+ record = iptool.cidr_to_ipv4('8.0.0.0/8')
61
+ expect(record).to include(
62
+ "ip_start"=>"8.0.0.0",
63
+ "ip_end"=>"8.255.255.255"
64
+ )
65
+ end
66
+
67
+ it "work correctly with iptools ipv6_to_cidr" do
68
+ iptool = Ip2locationIpTools.new()
69
+ record = iptool.ipv6_to_cidr('2002:0000:0000:1234:abcd:ffff:c0a8:0000', '2002:0000:0000:1234:ffff:ffff:ffff:ffff')
70
+ expect(record).to eq ['2002::1234:abcd:ffff:c0a8:0/109','2002::1234:abcd:ffff:c0b0:0/108','2002::1234:abcd:ffff:c0c0:0/106','2002::1234:abcd:ffff:c100:0/104','2002::1234:abcd:ffff:c200:0/103','2002::1234:abcd:ffff:c400:0/102','2002::1234:abcd:ffff:c800:0/101','2002::1234:abcd:ffff:d000:0/100','2002::1234:abcd:ffff:e000:0/99','2002:0:0:1234:abce::/79','2002:0:0:1234:abd0::/76','2002:0:0:1234:abe0::/75','2002:0:0:1234:ac00::/70','2002:0:0:1234:b000::/68','2002:0:0:1234:c000::/66']
71
+ end
72
+
73
+ it "work correctly with iptools cidr_to_ipv6" do
74
+ iptool = Ip2locationIpTools.new()
75
+ record = iptool.cidr_to_ipv6('2002::1234:abcd:ffff:c0a8:101/64')
76
+ expect(record).to include(
77
+ "ip_start"=>"2002:0000:0000:1234:abcd:ffff:c0a8:0101",
78
+ "ip_end"=>"2002:0000:0000:1234:ffff:ffff:ffff:ffff"
79
+ )
80
+ end
81
+
82
+ it "work correctly with iptools compress_ipv6" do
83
+ iptool = Ip2locationIpTools.new()
84
+ record = iptool.compress_ipv6('2002:0000:0000:1234:ffff:ffff:ffff:ffff')
85
+ expect(record).to eq '2002::1234:ffff:ffff:ffff:ffff'
86
+ end
87
+
88
+ it "work correctly with iptools expand_ipv6" do
89
+ iptool = Ip2locationIpTools.new()
90
+ record = iptool.expand_ipv6('2002::1234:ffff:ffff:ffff:ffff')
91
+ expect(record).to eq '2002:0000:0000:1234:ffff:ffff:ffff:ffff'
92
+ end
93
+
94
+ end
@@ -10,6 +10,6 @@ describe "Ip2location" do
10
10
  it "work correctly with web service get_credit" do
11
11
  ws = Ip2locationWebService.new('demo', 'WS25', true)
12
12
  record = ws.get_credit()
13
- expect(record).to_not eq 0
13
+ expect(record).to eq 0
14
14
  end
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ip2location_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.3.2
4
+ version: 8.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ip2location
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-07 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -97,6 +97,7 @@ files:
97
97
  - rb/data/IP2LOCATION-LITE-DB1.IPV6.BIN
98
98
  - spec/assets/IP2LOCATION-LITE-DB1.IPV6.BIN
99
99
  - spec/ip2location_ruby_database_spec.rb
100
+ - spec/ip2location_ruby_iptools_spec.rb
100
101
  - spec/ip2location_ruby_webservice_spec.rb
101
102
  - spec/spec_helper.rb
102
103
  homepage: https://github.com/ip2location/ip2location-ruby
@@ -107,7 +108,7 @@ metadata:
107
108
  documentation_uri: https://www.rubydoc.info/gems/ip2location_ruby
108
109
  homepage_uri: https://www.ip2location.com
109
110
  source_code_uri: https://github.com/ip2location/ip2location-ruby
110
- post_install_message:
111
+ post_install_message:
111
112
  rdoc_options: []
112
113
  require_paths:
113
114
  - lib
@@ -122,9 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubyforge_project:
126
- rubygems_version: 2.7.6.2
127
- signing_key:
126
+ rubygems_version: 3.2.33
127
+ signing_key:
128
128
  specification_version: 4
129
129
  summary: the ip2location ruby library
130
130
  test_files: []