ip2location_ruby 8.2.3 → 8.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: 118e20ce9246a282a4762523c68870f645bde1532e79950e812e935eecc4252e
4
- data.tar.gz: 23da14c93843dc1952371b5f250015d59fdf27323fcc0232882f65a036509a86
3
+ metadata.gz: e745f1d50bac46096d52e3b092873502999f28659108f701221225a015038865
4
+ data.tar.gz: 867a13f878805690873255278b61b03d554a143108fa099ccbbac3048808e0e0
5
5
  SHA512:
6
- metadata.gz: 5d1da0f2aed10f79b0268e38368abaaa66b8c2e5f24a862fb46fd6c5c58047f6e5a15941561ba527020fcd312aa62f1c8e918fc8273ffa25ba6f4a3e6847a834
7
- data.tar.gz: f1481d6b6bfd5143612c6772a4c9be2d2f0216e74293afa80b1fcba422755016a27167c99640880e1fda45577e3cee7b69b3398a7f7fe89b68f7394e418614f9
6
+ metadata.gz: 569481b686f7ba1895982a6ccb38f77550df6406fe1e4dba889e6a425f01bf5db22c67abe58ea4e67e9d49c69cb96d23ab347b25be65f254ba8c0aebca700b84
7
+ data.tar.gz: 11721c250f7ed16ffb89c681678dc03a0eb39090857d85e38400e806399e9fae429738b686422208aa87ca81dcd134a049d35a83c5d1511158e7db46cec22bed
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020 IP2Location ( support@ip2location.com )
1
+ Copyright (c) 2021 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
@@ -2,7 +2,7 @@
2
2
  [![Total Downloads](https://img.shields.io/gem/dt/ip2location_ruby.svg)](https://rubygems.org/gems/ip2location_ruby)
3
3
 
4
4
  # IP2Location Ruby Library
5
- This is IP2Location Ruby library that enables the user to find the country, region or state, city, latitude and longitude, US ZIP code, time zone, Internet Service Provider (ISP) or company name, domain name, net speed, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC) and carrier brand, elevation, and usage type by IP address or hostname originates from. The library reads the geo location information from **IP2Location BIN data** file or web service.
5
+ This is IP2Location Ruby library that enables the user to find the country, region or state, city, latitude and longitude, US ZIP code, time zone, Internet Service Provider (ISP) or company name, domain name, net speed, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC) and carrier brand, elevation, usage type, IP address type and IAB advertising category from IP address using IP2Location database. The library reads the geo location information from **IP2Location BIN data** file or web service.
6
6
 
7
7
  Supported IPv4 and IPv6 address.
8
8
 
@@ -19,6 +19,10 @@ Below is the description of the functions available in the **BIN Database** look
19
19
  |---|---|
20
20
  | open | Open the IP2Location BIN data for lookup. |
21
21
  | close | Close and clean up the file pointer. |
22
+ | get_package_version | Get the package version (1 to 25 for DB1 to DB25 respectively). |
23
+ | get_module_version | Get the module version. |
24
+ | get_database_version | Get the database version. |
25
+ | get_last_error_message | Return the last error message. |
22
26
  | get_all | Return the geolocation information in array. |
23
27
  | get_country_short | Return the ISO3166-1 country code (2-digits) of the IP address. |
24
28
  | get_country_long | Return the ISO3166-1 country name of the IP address. |
@@ -40,6 +44,8 @@ Below is the description of the functions available in the **BIN Database** look
40
44
  | get_mobilebrand | Commercial brand associated with the mobile carrier. |
41
45
  | get_elevation | Return average height of city above sea level in meters (m). |
42
46
  | get_usagetype | Return the ISP's usage type of IP address. |
47
+ | get_addresstype | Returns the IP address type (A-Anycast, B-Broadcast, M-Multicast & U-Unicast) of IP address or domain name. |
48
+ | category | Returns the IAB content taxonomy category of IP address or domain name. |
43
49
 
44
50
 
45
51
  ## Web Service
@@ -47,8 +53,8 @@ Below is the description of the functions available in the **Web Service** looku
47
53
 
48
54
  | Function Name | Description |
49
55
  |---|---|
50
- | Constructor | Expect 3 input parameters:<ol><li>IP2Location API Key.</li><li>Package (WS1 - WS24)</li></li><li>Use HTTPS or HTTP</li></ol> |
51
- | 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>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> |
56
+ | Constructor | Expect 3 input parameters:<ol><li>IP2Location API Key.</li><li>Package (WS1 - WS25)</li></li><li>Use HTTPS or HTTP</li></ol> |
57
+ | 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> |
52
58
  | get_credit | Return remaining credit of the web service account. |
53
59
 
54
60
  # Dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.2.3
1
+ 8.3.0
data/example.rb CHANGED
@@ -30,11 +30,13 @@ print 'Elevation: '
30
30
  print record['elevation']
31
31
  print "\n"
32
32
  print 'Usage Type: ' + record['usagetype'] + "\n"
33
+ print 'Address Type: ' + record['addresstype'] + "\n"
34
+ print 'Category: ' + record['category'] + "\n"
33
35
 
34
36
  i2l.close()
35
37
 
36
38
  # Web Service
37
- ws = Ip2locationWebService.new('demo', 'WS24', true)
39
+ ws = Ip2locationWebService.new('demo', 'WS25', true)
38
40
  record = ws.lookup('8.8.8.8', 'continent,country,region,city,geotargeting,country_groupings,time_zone_info', 'en')
39
41
  print record
40
42
  print "\n"
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ip2location_ruby"
8
- s.version = "8.2.3"
8
+ s.version = "8.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.require_paths = ["lib"]
@@ -11,16 +11,42 @@ require 'ip2location_ruby/i2l_ip_data'
11
11
  require 'ip2location_ruby/ip2location_record'
12
12
 
13
13
  class Ip2location
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
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.0'
16
17
  FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
17
18
  INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
19
+ INVALID_BIN_DATABASE = 'Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file.'
20
+ IPV6_ADDRESS_IN_IPV4_BIN = 'IPV6 ADDRESS MISSING IN IPV4 BIN'
18
21
 
19
22
  def open(url)
20
- self.file = File.open(File.expand_path url, 'rb')
23
+ if url == ''
24
+ self.last_err_msg = 'Ip2location.new.open() requires a database path name.'
25
+ abort('Ip2location.new.open() requires a database path name.')
26
+ end
27
+
28
+ begin
29
+ self.file = File.open(File.expand_path url, 'rb')
30
+ rescue
31
+ self.last_err_msg = 'Ip2location.new.open() error in opening ' + url +'.'
32
+ abort('Ip2location.new.open() error in opening ' + url +'.')
33
+ else
34
+ end
21
35
  i2l = Ip2locationConfig.read(file)
36
+ if i2l.productcode == 1
37
+ else
38
+ if i2l.databaseyear <= 20 && i2l.productcode == 0
39
+ else
40
+ self.file.close
41
+ self.last_err_msg = INVALID_BIN_DATABASE
42
+ abort(INVALID_BIN_DATABASE)
43
+ end
44
+ end
22
45
  self.db_index = i2l.databasetype
23
46
  self.columns = i2l.databasecolumn + 0
47
+ self.databaseyear = 2000 + i2l.databaseyear
48
+ self.databasemonth = i2l.databasemonth
49
+ self.databaseday = i2l.databaseday
24
50
  self.database = DbConfig.setup_database(self.db_index)
25
51
  self.ipv4databasecount = i2l.ipv4databasecount
26
52
  self.ipv4databaseaddr = i2l.ipv4databaseaddr
@@ -37,12 +63,31 @@ class Ip2location
37
63
  self.file.close
38
64
  end
39
65
 
66
+ def get_last_error_message()
67
+ return self.last_err_msg
68
+ end
69
+
70
+ def get_module_version()
71
+ return VERSION
72
+ end
73
+
74
+ def get_package_version()
75
+ return (self.db_index).to_s
76
+ end
77
+
78
+ def get_database_version()
79
+ return (self.databaseyear).to_s + "." + (self.databasemonth).to_s + "." + (self.databaseday).to_s
80
+ end
81
+
40
82
  def get_record(ip)
41
83
  ipno = IPAddr.new(ip, Socket::AF_UNSPEC)
42
84
  self.ip_version, ipnum = validateip(ipno)
43
85
  self.v4 = ip_version == 4 ? true : false
44
86
  self.count = v4 ? self.ipv4databasecount + 0 : self.ipv6databasecount + 0
45
87
  self.base_addr = (v4 ? self.ipv4databaseaddr - 1 : self.ipv6databaseaddr - 1)
88
+ if ip_version == 6 && self.ipv6databasecount == 0
89
+ return IPV6_ADDRESS_IN_IPV4_BIN
90
+ end
46
91
  col_length = columns * 4
47
92
  if ipv4indexbaseaddr > 0 || ipv6indexbaseaddr > 0
48
93
  indexpos = 0
@@ -74,7 +119,30 @@ class Ip2location
74
119
  valid = !(IPAddr.new(ip) rescue nil).nil?
75
120
  if valid
76
121
  rec = get_record(ip)
77
- if !(rec.nil?)
122
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
123
+ country_short = IPV6_ADDRESS_IN_IPV4_BIN
124
+ country_long = IPV6_ADDRESS_IN_IPV4_BIN
125
+ region = IPV6_ADDRESS_IN_IPV4_BIN
126
+ city = IPV6_ADDRESS_IN_IPV4_BIN
127
+ latitude = IPV6_ADDRESS_IN_IPV4_BIN
128
+ longitude = IPV6_ADDRESS_IN_IPV4_BIN
129
+ isp = IPV6_ADDRESS_IN_IPV4_BIN
130
+ domain = IPV6_ADDRESS_IN_IPV4_BIN
131
+ netspeed = IPV6_ADDRESS_IN_IPV4_BIN
132
+ areacode = IPV6_ADDRESS_IN_IPV4_BIN
133
+ iddcode = IPV6_ADDRESS_IN_IPV4_BIN
134
+ timezone = IPV6_ADDRESS_IN_IPV4_BIN
135
+ zipcode = IPV6_ADDRESS_IN_IPV4_BIN
136
+ weatherstationname = IPV6_ADDRESS_IN_IPV4_BIN
137
+ weatherstationcode = IPV6_ADDRESS_IN_IPV4_BIN
138
+ mcc = IPV6_ADDRESS_IN_IPV4_BIN
139
+ mnc = IPV6_ADDRESS_IN_IPV4_BIN
140
+ mobilebrand = IPV6_ADDRESS_IN_IPV4_BIN
141
+ elevation = IPV6_ADDRESS_IN_IPV4_BIN
142
+ usagetype = IPV6_ADDRESS_IN_IPV4_BIN
143
+ addresstype = IPV6_ADDRESS_IN_IPV4_BIN
144
+ category = IPV6_ADDRESS_IN_IPV4_BIN
145
+ elsif !(rec.nil?)
78
146
  country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
79
147
  country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
80
148
  region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
@@ -95,6 +163,8 @@ class Ip2location
95
163
  mobilebrand = (defined?(rec.mobilebrand) && rec.mobilebrand != '') ? rec.mobilebrand : FIELD_NOT_SUPPORTED
96
164
  elevation = (defined?(rec.elevation) && rec.elevation != '') ? rec.elevation : FIELD_NOT_SUPPORTED
97
165
  usagetype = (defined?(rec.usagetype) && rec.usagetype != '') ? rec.usagetype : FIELD_NOT_SUPPORTED
166
+ addresstype = (defined?(rec.addresstype) && rec.addresstype != '') ? rec.addresstype : FIELD_NOT_SUPPORTED
167
+ category = (defined?(rec.category) && rec.category != '') ? rec.category : FIELD_NOT_SUPPORTED
98
168
  else
99
169
  country_short = INVALID_IP_ADDRESS
100
170
  country_long = INVALID_IP_ADDRESS
@@ -116,6 +186,8 @@ class Ip2location
116
186
  mobilebrand = INVALID_IP_ADDRESS
117
187
  elevation = INVALID_IP_ADDRESS
118
188
  usagetype = INVALID_IP_ADDRESS
189
+ addresstype = INVALID_IP_ADDRESS
190
+ category = INVALID_IP_ADDRESS
119
191
  end
120
192
  else
121
193
  country_short = INVALID_IP_ADDRESS
@@ -138,6 +210,8 @@ class Ip2location
138
210
  mobilebrand = INVALID_IP_ADDRESS
139
211
  elevation = INVALID_IP_ADDRESS
140
212
  usagetype = INVALID_IP_ADDRESS
213
+ addresstype = INVALID_IP_ADDRESS
214
+ category = INVALID_IP_ADDRESS
141
215
  end
142
216
  results = {}
143
217
  results['country_short'] = country_short
@@ -160,6 +234,8 @@ class Ip2location
160
234
  results['mobilebrand'] = mobilebrand
161
235
  results['elevation'] = elevation
162
236
  results['usagetype'] = usagetype
237
+ results['addresstype'] = addresstype
238
+ results['category'] = category
163
239
  return results
164
240
  end
165
241
 
@@ -167,7 +243,9 @@ class Ip2location
167
243
  valid = !(IPAddr.new(ip) rescue nil).nil?
168
244
  if valid
169
245
  rec = get_record(ip)
170
- if !(rec.nil?)
246
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
247
+ country_short = IPV6_ADDRESS_IN_IPV4_BIN
248
+ elsif !(rec.nil?)
171
249
  country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
172
250
  else
173
251
  country_short = INVALID_IP_ADDRESS
@@ -182,7 +260,9 @@ class Ip2location
182
260
  valid = !(IPAddr.new(ip) rescue nil).nil?
183
261
  if valid
184
262
  rec = get_record(ip)
185
- if !(rec.nil?)
263
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
264
+ country_long = IPV6_ADDRESS_IN_IPV4_BIN
265
+ elsif !(rec.nil?)
186
266
  country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
187
267
  else
188
268
  country_long = INVALID_IP_ADDRESS
@@ -197,7 +277,9 @@ class Ip2location
197
277
  valid = !(IPAddr.new(ip) rescue nil).nil?
198
278
  if valid
199
279
  rec = get_record(ip)
200
- if !(rec.nil?)
280
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
281
+ region = IPV6_ADDRESS_IN_IPV4_BIN
282
+ elsif !(rec.nil?)
201
283
  region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
202
284
  else
203
285
  region = INVALID_IP_ADDRESS
@@ -212,7 +294,9 @@ class Ip2location
212
294
  valid = !(IPAddr.new(ip) rescue nil).nil?
213
295
  if valid
214
296
  rec = get_record(ip)
215
- if !(rec.nil?)
297
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
298
+ city = IPV6_ADDRESS_IN_IPV4_BIN
299
+ elsif !(rec.nil?)
216
300
  city = (defined?(rec.city) && rec.city != '') ? rec.city : FIELD_NOT_SUPPORTED
217
301
  else
218
302
  city = INVALID_IP_ADDRESS
@@ -227,7 +311,9 @@ class Ip2location
227
311
  valid = !(IPAddr.new(ip) rescue nil).nil?
228
312
  if valid
229
313
  rec = get_record(ip)
230
- if !(rec.nil?)
314
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
315
+ latitude = IPV6_ADDRESS_IN_IPV4_BIN
316
+ elsif !(rec.nil?)
231
317
  latitude = (defined?(rec.latitude) && rec.latitude != '') ? rec.latitude : FIELD_NOT_SUPPORTED
232
318
  else
233
319
  latitude = INVALID_IP_ADDRESS
@@ -242,7 +328,9 @@ class Ip2location
242
328
  valid = !(IPAddr.new(ip) rescue nil).nil?
243
329
  if valid
244
330
  rec = get_record(ip)
245
- if !(rec.nil?)
331
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
332
+ longitude = IPV6_ADDRESS_IN_IPV4_BIN
333
+ elsif !(rec.nil?)
246
334
  longitude = (defined?(rec.longitude) && rec.longitude != '') ? rec.longitude : FIELD_NOT_SUPPORTED
247
335
  else
248
336
  longitude = INVALID_IP_ADDRESS
@@ -257,7 +345,9 @@ class Ip2location
257
345
  valid = !(IPAddr.new(ip) rescue nil).nil?
258
346
  if valid
259
347
  rec = get_record(ip)
260
- if !(rec.nil?)
348
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
349
+ isp = IPV6_ADDRESS_IN_IPV4_BIN
350
+ elsif !(rec.nil?)
261
351
  isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED
262
352
  else
263
353
  isp = INVALID_IP_ADDRESS
@@ -272,7 +362,9 @@ class Ip2location
272
362
  valid = !(IPAddr.new(ip) rescue nil).nil?
273
363
  if valid
274
364
  rec = get_record(ip)
275
- if !(rec.nil?)
365
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
366
+ domain = IPV6_ADDRESS_IN_IPV4_BIN
367
+ elsif !(rec.nil?)
276
368
  domain = (defined?(rec.domain) && rec.domain != '') ? rec.domain : FIELD_NOT_SUPPORTED
277
369
  else
278
370
  domain = INVALID_IP_ADDRESS
@@ -287,7 +379,9 @@ class Ip2location
287
379
  valid = !(IPAddr.new(ip) rescue nil).nil?
288
380
  if valid
289
381
  rec = get_record(ip)
290
- if !(rec.nil?)
382
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
383
+ zipcode = IPV6_ADDRESS_IN_IPV4_BIN
384
+ elsif !(rec.nil?)
291
385
  zipcode = (defined?(rec.zipcode) && rec.zipcode != '') ? rec.zipcode : FIELD_NOT_SUPPORTED
292
386
  else
293
387
  zipcode = INVALID_IP_ADDRESS
@@ -302,7 +396,9 @@ class Ip2location
302
396
  valid = !(IPAddr.new(ip) rescue nil).nil?
303
397
  if valid
304
398
  rec = get_record(ip)
305
- if !(rec.nil?)
399
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
400
+ timezone = IPV6_ADDRESS_IN_IPV4_BIN
401
+ elsif !(rec.nil?)
306
402
  timezone = (defined?(rec.timezone) && rec.timezone != '') ? rec.timezone : FIELD_NOT_SUPPORTED
307
403
  else
308
404
  timezone = INVALID_IP_ADDRESS
@@ -317,7 +413,9 @@ class Ip2location
317
413
  valid = !(IPAddr.new(ip) rescue nil).nil?
318
414
  if valid
319
415
  rec = get_record(ip)
320
- if !(rec.nil?)
416
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
417
+ netspeed = IPV6_ADDRESS_IN_IPV4_BIN
418
+ elsif !(rec.nil?)
321
419
  netspeed = (defined?(rec.netspeed) && rec.netspeed != '') ? rec.netspeed : FIELD_NOT_SUPPORTED
322
420
  else
323
421
  netspeed = INVALID_IP_ADDRESS
@@ -332,7 +430,9 @@ class Ip2location
332
430
  valid = !(IPAddr.new(ip) rescue nil).nil?
333
431
  if valid
334
432
  rec = get_record(ip)
335
- if !(rec.nil?)
433
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
434
+ iddcode = IPV6_ADDRESS_IN_IPV4_BIN
435
+ elsif !(rec.nil?)
336
436
  iddcode = (defined?(rec.iddcode) && rec.iddcode != '') ? rec.iddcode : FIELD_NOT_SUPPORTED
337
437
  else
338
438
  iddcode = INVALID_IP_ADDRESS
@@ -347,7 +447,9 @@ class Ip2location
347
447
  valid = !(IPAddr.new(ip) rescue nil).nil?
348
448
  if valid
349
449
  rec = get_record(ip)
350
- if !(rec.nil?)
450
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
451
+ areacode = IPV6_ADDRESS_IN_IPV4_BIN
452
+ elsif !(rec.nil?)
351
453
  areacode = (defined?(rec.areacode) && rec.areacode != '') ? rec.areacode : FIELD_NOT_SUPPORTED
352
454
  else
353
455
  areacode = INVALID_IP_ADDRESS
@@ -362,7 +464,9 @@ class Ip2location
362
464
  valid = !(IPAddr.new(ip) rescue nil).nil?
363
465
  if valid
364
466
  rec = get_record(ip)
365
- if !(rec.nil?)
467
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
468
+ weatherstationcode = IPV6_ADDRESS_IN_IPV4_BIN
469
+ elsif !(rec.nil?)
366
470
  weatherstationcode = (defined?(rec.weatherstationcode) && rec.weatherstationcode != '') ? rec.weatherstationcode : FIELD_NOT_SUPPORTED
367
471
  else
368
472
  weatherstationcode = INVALID_IP_ADDRESS
@@ -377,7 +481,9 @@ class Ip2location
377
481
  valid = !(IPAddr.new(ip) rescue nil).nil?
378
482
  if valid
379
483
  rec = get_record(ip)
380
- if !(rec.nil?)
484
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
485
+ weatherstationname = IPV6_ADDRESS_IN_IPV4_BIN
486
+ elsif !(rec.nil?)
381
487
  weatherstationname = (defined?(rec.weatherstationname) && rec.weatherstationname != '') ? rec.weatherstationname : FIELD_NOT_SUPPORTED
382
488
  else
383
489
  weatherstationname = INVALID_IP_ADDRESS
@@ -392,7 +498,9 @@ class Ip2location
392
498
  valid = !(IPAddr.new(ip) rescue nil).nil?
393
499
  if valid
394
500
  rec = get_record(ip)
395
- if !(rec.nil?)
501
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
502
+ mcc = IPV6_ADDRESS_IN_IPV4_BIN
503
+ elsif !(rec.nil?)
396
504
  mcc = (defined?(rec.mcc) && rec.mcc != '') ? rec.mcc : FIELD_NOT_SUPPORTED
397
505
  else
398
506
  mcc = INVALID_IP_ADDRESS
@@ -407,7 +515,9 @@ class Ip2location
407
515
  valid = !(IPAddr.new(ip) rescue nil).nil?
408
516
  if valid
409
517
  rec = get_record(ip)
410
- if !(rec.nil?)
518
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
519
+ mnc = IPV6_ADDRESS_IN_IPV4_BIN
520
+ elsif !(rec.nil?)
411
521
  mnc = (defined?(rec.mnc) && rec.mnc != '') ? rec.mnc : FIELD_NOT_SUPPORTED
412
522
  else
413
523
  mnc = INVALID_IP_ADDRESS
@@ -422,7 +532,9 @@ class Ip2location
422
532
  valid = !(IPAddr.new(ip) rescue nil).nil?
423
533
  if valid
424
534
  rec = get_record(ip)
425
- if !(rec.nil?)
535
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
536
+ mobilebrand = IPV6_ADDRESS_IN_IPV4_BIN
537
+ elsif !(rec.nil?)
426
538
  mobilebrand = (defined?(rec.mobilebrand) && rec.mobilebrand != '') ? rec.mobilebrand : FIELD_NOT_SUPPORTED
427
539
  else
428
540
  mobilebrand = INVALID_IP_ADDRESS
@@ -437,7 +549,9 @@ class Ip2location
437
549
  valid = !(IPAddr.new(ip) rescue nil).nil?
438
550
  if valid
439
551
  rec = get_record(ip)
440
- if !(rec.nil?)
552
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
553
+ elevation = IPV6_ADDRESS_IN_IPV4_BIN
554
+ elsif !(rec.nil?)
441
555
  elevation = (defined?(rec.elevation) && rec.elevation != '') ? rec.elevation : FIELD_NOT_SUPPORTED
442
556
  else
443
557
  elevation = INVALID_IP_ADDRESS
@@ -452,7 +566,9 @@ class Ip2location
452
566
  valid = !(IPAddr.new(ip) rescue nil).nil?
453
567
  if valid
454
568
  rec = get_record(ip)
455
- if !(rec.nil?)
569
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
570
+ usagetype = IPV6_ADDRESS_IN_IPV4_BIN
571
+ elsif !(rec.nil?)
456
572
  usagetype = (defined?(rec.usagetype) && rec.usagetype != '') ? rec.usagetype : FIELD_NOT_SUPPORTED
457
573
  else
458
574
  usagetype = INVALID_IP_ADDRESS
@@ -463,6 +579,40 @@ class Ip2location
463
579
  return usagetype
464
580
  end
465
581
 
582
+ def get_addresstype(ip)
583
+ valid = !(IPAddr.new(ip) rescue nil).nil?
584
+ if valid
585
+ rec = get_record(ip)
586
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
587
+ addresstype = IPV6_ADDRESS_IN_IPV4_BIN
588
+ elsif !(rec.nil?)
589
+ addresstype = (defined?(rec.addresstype) && rec.addresstype != '') ? rec.addresstype : FIELD_NOT_SUPPORTED
590
+ else
591
+ addresstype = INVALID_IP_ADDRESS
592
+ end
593
+ else
594
+ addresstype = INVALID_IP_ADDRESS
595
+ end
596
+ return addresstype
597
+ end
598
+
599
+ def get_category(ip)
600
+ valid = !(IPAddr.new(ip) rescue nil).nil?
601
+ if valid
602
+ rec = get_record(ip)
603
+ if rec == IPV6_ADDRESS_IN_IPV4_BIN
604
+ category = IPV6_ADDRESS_IN_IPV4_BIN
605
+ elsif !(rec.nil?)
606
+ category = (defined?(rec.category) && rec.category != '') ? rec.category : FIELD_NOT_SUPPORTED
607
+ else
608
+ category = INVALID_IP_ADDRESS
609
+ end
610
+ else
611
+ category = INVALID_IP_ADDRESS
612
+ end
613
+ return category
614
+ end
615
+
466
616
  def bsearch(low, high, ipnum, base_addr, col_length)
467
617
  while low <= high do
468
618
  mid = (low + high) >> 1
@@ -1,24 +1,26 @@
1
1
  class DbConfig
2
2
  COLUMNS = {
3
- :COUNTRY => [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
4
- :REGION => [0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
5
- :CITY => [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
6
- :ISP => [0, 0, 3, 0, 5, 0, 7, 5, 7, 0, 8, 0, 9, 0, 9, 0, 9, 0, 9, 7, 9, 0, 9, 7, 9],
7
- :LATITUDE => [0, 0, 0, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
8
- :LONGITUDE => [0, 0, 0, 0, 0, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],
9
- :DOMAIN => [0, 0, 0, 0, 0, 0, 0, 6, 8, 0, 9, 0, 10, 0, 10, 0, 10, 0, 10, 8, 10, 0, 10, 8, 10],
10
- :ZIPCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 7, 7, 7, 0, 7, 0, 7, 7, 7, 0, 7],
11
- :TIMEZONE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 7, 8, 8, 8, 7, 8, 0, 8, 8, 8, 0, 8],
12
- :NETSPEED => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 11, 0, 11,8, 11, 0, 11, 0, 11, 0, 11],
13
- :IDDCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 12, 0, 12, 0, 12, 9, 12, 0, 12],
14
- :AREACODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10 ,13 ,0, 13, 0, 13, 10, 13, 0, 13],
15
- :WEATHERSTATIONCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 14, 0, 14, 0, 14, 0, 14],
16
- :WEATHERSTATIONNAME => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 15, 0, 15, 0, 15, 0, 15],
17
- :MCC => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 16, 0, 16, 9, 16],
18
- :MNC => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10,17, 0, 17, 10, 17],
19
- :MOBILEBRAND => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11,18, 0, 18, 11, 18],
20
- :ELEVATION => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 19, 0, 19],
21
- :USAGETYPE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 20]
3
+ :COUNTRY => [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
4
+ :REGION => [0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
5
+ :CITY => [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
6
+ :LATITUDE => [0, 0, 0, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
7
+ :LONGITUDE => [0, 0, 0, 0, 0, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],
8
+ :ZIPCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 7, 7, 7, 0, 7, 0, 7, 7, 7, 0, 7, 7],
9
+ :TIMEZONE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 7, 8, 8, 8, 7, 8, 0, 8, 8, 8, 0, 8, 8],
10
+ :ISP => [0, 0, 3, 0, 5, 0, 7, 5, 7, 0, 8, 0, 9, 0, 9, 0, 9, 0, 9, 7, 9, 0, 9, 7, 9, 9],
11
+ :DOMAIN => [0, 0, 0, 0, 0, 0, 0, 6, 8, 0, 9, 0, 10, 0, 10, 0, 10, 0, 10, 8, 10, 0, 10, 8, 10, 10],
12
+ :NETSPEED => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 11, 0, 11,8, 11, 0, 11, 0, 11, 0, 11, 11],
13
+ :IDDCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 12, 0, 12, 0, 12, 9, 12, 0, 12, 12],
14
+ :AREACODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10 ,13 ,0, 13, 0, 13, 10, 13, 0, 13, 13],
15
+ :WEATHERSTATIONCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 14, 0, 14, 0, 14, 0, 14, 14],
16
+ :WEATHERSTATIONNAME => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 15, 0, 15, 0, 15, 0, 15, 15],
17
+ :MCC => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 16, 0, 16, 9, 16, 16],
18
+ :MNC => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10,17, 0, 17, 10, 17, 17],
19
+ :MOBILEBRAND => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11,18, 0, 18, 11, 18, 18],
20
+ :ELEVATION => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 19, 0, 19, 19],
21
+ :USAGETYPE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 20, 20],
22
+ :ADDRESSTYPE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21],
23
+ :CATEGORY => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22]
22
24
  }
23
25
 
24
26
  def self.setup_database(db_index)
@@ -1,17 +1,20 @@
1
1
  class Ip2locationConfig < BinData::Record
2
2
  endian :little
3
- uint8 :databasetype
4
- uint8 :databasecolumn
5
- uint8 :databaseday
6
- uint8 :databasemonth
7
- uint8 :databaseyear
8
- # uint32 :databasecount
9
- # uint32 :databaseaddr
10
- # uint32 :ipversion
3
+ uint8 :databasetype
4
+ uint8 :databasecolumn
5
+ uint8 :databaseyear
6
+ uint8 :databasemonth
7
+ uint8 :databaseday
8
+ # uint32 :databasecount
9
+ # uint32 :databaseaddr
10
+ # uint32 :ipversion
11
11
  uint32 :ipv4databasecount
12
12
  uint32 :ipv4databaseaddr
13
13
  uint32 :ipv6databasecount
14
14
  uint32 :ipv6databaseaddr
15
15
  uint32 :ipv4indexbaseaddr
16
16
  uint32 :ipv6indexbaseaddr
17
+ uint8 :productcode
18
+ uint8 :licensecode
19
+ uint32 :databasesize
17
20
  end
Binary file
@@ -127,6 +127,18 @@ describe "Ip2location" do
127
127
  expect(record).to eq 'NOT SUPPORTED'
128
128
  end
129
129
 
130
+ it "work correctly with get_addresstype" do
131
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
132
+ record = i2l.get_addresstype('8.8.8.8')
133
+ expect(record).to eq 'NOT SUPPORTED'
134
+ end
135
+
136
+ it "work correctly with get_category" do
137
+ i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
138
+ record = i2l.get_category('8.8.8.8')
139
+ expect(record).to eq 'NOT SUPPORTED'
140
+ end
141
+
130
142
  it "work correctly with ipv6" do
131
143
  i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
132
144
  record = i2l.get_all('2001:4860:4860::8888')
@@ -2,13 +2,13 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Ip2location" do
4
4
  it "work correctly with web service lookup" do
5
- ws = Ip2locationWebService.new('demo', 'WS24', true)
5
+ ws = Ip2locationWebService.new('demo', 'WS25', true)
6
6
  record = ws.lookup('8.8.8.8', '', 'en')
7
7
  expect(record['country_code']).to eq 'US'
8
8
  end
9
9
 
10
10
  it "work correctly with web service get_credit" do
11
- ws = Ip2locationWebService.new('demo', 'WS24', true)
11
+ ws = Ip2locationWebService.new('demo', 'WS25', true)
12
12
  record = ws.get_credit()
13
13
  expect(record).to_not eq 0
14
14
  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.2.3
4
+ version: 8.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ip2location
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-28 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata