geoip 1.6.2 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/geoip.rb +84 -80
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0fbea1dc4ed77b0dbdb77c24bbea36c3157648a
4
- data.tar.gz: 2bd5fcf48e46090d0b78383822d547304f4cbacd
3
+ metadata.gz: c3520d7b15c106de43cc9c269bcec4cb371016f9
4
+ data.tar.gz: 0e88256388fb9550337811db7662a8c3bec6a57d
5
5
  SHA512:
6
- metadata.gz: 5be733f5691c1c1096e638ecbd9831cb7387aaf55ae118a9bf7c1bb7eaee1c5f0eab890e3c172286f345029bc19df63584f8eeb5bdea01539592aa94768d36d1
7
- data.tar.gz: 5a808dc0dfc62714d422b6f75e35b2b3123e58357c79ef34714d1f78a0f8d5b4d8285aa8db5f29b1864eb7cfaed4dbe917f6c9f4afe55d09ff4d6e76248972af
6
+ metadata.gz: f583b543af13df3e630880c81be10f7a958e2fcd91aab4d7b1842b6322104c35bd60abb9c124b03fb8202a55ee0c5817505890dd22d5f633fe420a097aab6393
7
+ data.tar.gz: 3a32e4572920f66b226ec59f9fd997271d6ba92faadc08fbcd3b12a6eb62c412610fd1a4427766582e2c14abc15b0c8911d5e9e8377b1c2b291115ee6964e391
@@ -58,7 +58,7 @@ require 'yaml'
58
58
  class GeoIP
59
59
 
60
60
  # The GeoIP GEM version number
61
- VERSION = "1.6.2"
61
+ VERSION = "1.6.3"
62
62
 
63
63
  # The +data/+ directory for geoip
64
64
  DATA_DIR = File.expand_path(File.join(File.dirname(__FILE__),'..','data','geoip'))
@@ -228,7 +228,8 @@ class GeoIP
228
228
  end
229
229
 
230
230
  @use_pread = IO.respond_to?(:pread) && !options[:preload]
231
-
231
+ @contents = nil
232
+ @iter_pos = nil
232
233
  @options = options
233
234
  @database_type = Edition::COUNTRY
234
235
  @record_length = STANDARD_RECORD_LENGTH
@@ -272,12 +273,12 @@ class GeoIP
272
273
  when Edition::COUNTRY, Edition::PROXY, Edition::COUNTRY_V6
273
274
  ip = lookup_ip(hostname)
274
275
  if @ip_bits > 32
275
- ipaddr = IPAddr.new ip
276
- code = (seek_record(ipaddr.to_i) - COUNTRY_BEGIN)
276
+ ipaddr = IPAddr.new ip
277
+ code = (seek_record(ipaddr.to_i) - COUNTRY_BEGIN)
277
278
  else
278
- # Convert numeric IP address to an integer
279
- ipnum = iptonum(ip)
280
- code = (seek_record(ipnum) - @database_segments[0])
279
+ # Convert numeric IP address to an integer
280
+ ipnum = iptonum(ip)
281
+ code = (seek_record(ipnum) - @database_segments[0])
281
282
  end
282
283
  read_country(code, hostname, ip)
283
284
  else
@@ -395,18 +396,18 @@ class GeoIP
395
396
 
396
397
  case @database_type
397
398
  when Edition::ORG,
398
- Edition::ISP,
399
- Edition::DOMAIN,
400
- Edition::ASNUM,
401
- Edition::ACCURACYRADIUS,
402
- Edition::NETSPEED,
403
- Edition::USERTYPE,
404
- Edition::REGISTRAR,
405
- Edition::LOCATIONA,
406
- Edition::CITYCONF,
407
- Edition::COUNTRYCONF,
408
- Edition::REGIONCONF,
409
- Edition::POSTALCONF
399
+ Edition::ISP,
400
+ Edition::DOMAIN,
401
+ Edition::ASNUM,
402
+ Edition::ACCURACYRADIUS,
403
+ Edition::NETSPEED,
404
+ Edition::USERTYPE,
405
+ Edition::REGISTRAR,
406
+ Edition::LOCATIONA,
407
+ Edition::CITYCONF,
408
+ Edition::COUNTRYCONF,
409
+ Edition::REGIONCONF,
410
+ Edition::POSTALCONF
410
411
  pos = seek_record(ipnum)
411
412
  read_isp(pos-@database_segments[0])
412
413
  else
@@ -430,14 +431,17 @@ class GeoIP
430
431
  def asn(hostname)
431
432
  ip = lookup_ip(hostname)
432
433
 
433
- # Convert numeric IP address to an integer
434
- ipnum = iptonum(ip)
435
-
436
- if ![Edition::ASNUM, Edition::ASNUM_V6].include? @database_type
434
+ if (@database_type == Edition::ASNUM)
435
+ # Convert numeric IP address to an integer
436
+ ipnum = iptonum(ip)
437
+ pos = seek_record(ipnum)
438
+ elsif (@database_type == Edition::ASNUM_V6)
439
+ ipaddr = IPAddr.new ip
440
+ pos = seek_record(ipaddr.to_i)
441
+ else
437
442
  throw "Invalid GeoIP database type #{@database_type}, can't look up ASN by IP"
438
443
  end
439
444
 
440
- pos = seek_record(ipnum)
441
445
  read_asn(pos-@database_segments[0])
442
446
  end
443
447
 
@@ -546,11 +550,11 @@ class GeoIP
546
550
  0.upto(STRUCTURE_INFO_MAX_SIZE - 1) do |i|
547
551
  if @file.read(3).bytes.all? { |byte| byte == 255 }
548
552
  @database_type =
549
- if @file.respond_to?(:getbyte)
550
- @file.getbyte
551
- else
552
- @file.getc
553
- end
553
+ if @file.respond_to?(:getbyte)
554
+ @file.getbyte
555
+ else
556
+ @file.getc
557
+ end
554
558
 
555
559
  @database_type -= 105 if @database_type >= 106
556
560
 
@@ -566,20 +570,20 @@ class GeoIP
566
570
  @database_type == Edition::ORG_V6 ||
567
571
  @database_type == Edition::ISP ||
568
572
  @database_type == Edition::ISP_V6 ||
569
- @database_type == Edition::REGISTRAR ||
570
- @database_type == Edition::REGISTRAR_V6 ||
571
- @database_type == Edition::USERTYPE || # Many of these files mis-identify as ASNUM files
572
- @database_type == Edition::USERTYPE_V6 ||
573
+ @database_type == Edition::REGISTRAR ||
574
+ @database_type == Edition::REGISTRAR_V6 ||
575
+ @database_type == Edition::USERTYPE || # Many of these files mis-identify as ASNUM files
576
+ @database_type == Edition::USERTYPE_V6 ||
573
577
  @database_type == Edition::DOMAIN ||
574
578
  @database_type == Edition::DOMAIN_V6 ||
575
579
  @database_type == Edition::ASNUM ||
576
580
  @database_type == Edition::ASNUM_V6 ||
577
- @database_type == Edition::NETSPEED_REV1 ||
578
- @database_type == Edition::NETSPEED_REV1_V6 ||
579
- @database_type == Edition::LOCATIONA ||
580
- # @database_type == Edition::LOCATIONA_V6 ||
581
- @database_type == Edition::ACCURACYRADIUS ||
582
- @database_type == Edition::ACCURACYRADIUS_V6 ||
581
+ @database_type == Edition::NETSPEED_REV1 ||
582
+ @database_type == Edition::NETSPEED_REV1_V6 ||
583
+ @database_type == Edition::LOCATIONA ||
584
+ # @database_type == Edition::LOCATIONA_V6 ||
585
+ @database_type == Edition::ACCURACYRADIUS ||
586
+ @database_type == Edition::ACCURACYRADIUS_V6 ||
583
587
  @database_type == Edition::CITYCONF ||
584
588
  @database_type == Edition::COUNTRYCONF ||
585
589
  @database_type == Edition::REGIONCONF ||
@@ -594,46 +598,46 @@ class GeoIP
594
598
 
595
599
  end
596
600
 
597
- case @database_type
598
- when Edition::COUNTRY
599
- when Edition::NETSPEED_REV1
600
- when Edition::ASNUM
601
- when Edition::CITY_REV0
602
- when Edition::CITY_REV1
603
- when Edition::REGION_REV0
604
- when Edition::REGION_REV1
605
- @ip_bits = 32
606
- @record_length = 3
607
-
608
- when Edition::ORG,
609
- Edition::DOMAIN,
610
- Edition::ISP
611
- @ip_bits = 32
612
- @record_length = 4
613
-
614
- when Edition::ASNUM_V6,
615
- Edition::CITY_REV0_V6,
616
- Edition::CITY_REV1_V6,
617
- Edition::NETSPEED_REV1_V6,
618
- Edition::COUNTRY_V6,
619
- Edition::PROXY
620
- @ip_bits = 128
621
- @record_length = 3
622
-
623
- when Edition::ACCURACYRADIUS_V6,
624
- Edition::DOMAIN_V6,
625
- Edition::ISP_V6,
626
- Edition::LARGE_COUNTRY_V6,
627
- Edition::LOCATIONA_V6,
628
- Edition::ORG_V6,
629
- Edition::REGISTRAR_V6,
630
- Edition::USERTYPE_V6
631
- @ip_bits = 128
632
- @record_length = 4
633
-
634
- else
635
- raise "unimplemented database type"
636
- end
601
+ case @database_type
602
+ when Edition::COUNTRY
603
+ when Edition::NETSPEED_REV1
604
+ when Edition::ASNUM
605
+ when Edition::CITY_REV0
606
+ when Edition::CITY_REV1
607
+ when Edition::REGION_REV0
608
+ when Edition::REGION_REV1
609
+ @ip_bits = 32
610
+ @record_length = 3
611
+
612
+ when Edition::ORG,
613
+ Edition::DOMAIN,
614
+ Edition::ISP
615
+ @ip_bits = 32
616
+ @record_length = 4
617
+
618
+ when Edition::ASNUM_V6,
619
+ Edition::CITY_REV0_V6,
620
+ Edition::CITY_REV1_V6,
621
+ Edition::NETSPEED_REV1_V6,
622
+ Edition::COUNTRY_V6,
623
+ Edition::PROXY
624
+ @ip_bits = 128
625
+ @record_length = 3
626
+
627
+ when Edition::ACCURACYRADIUS_V6,
628
+ Edition::DOMAIN_V6,
629
+ Edition::ISP_V6,
630
+ Edition::LARGE_COUNTRY_V6,
631
+ Edition::LOCATIONA_V6,
632
+ Edition::ORG_V6,
633
+ Edition::REGISTRAR_V6,
634
+ Edition::USERTYPE_V6
635
+ @ip_bits = 128
636
+ @record_length = 4
637
+
638
+ else
639
+ raise "unimplemented database type"
640
+ end
637
641
 
638
642
  break
639
643
  else
@@ -697,7 +701,7 @@ class GeoIP
697
701
  CountryCode3[code], # ISO3166-2 alpha-3 code
698
702
  CountryName[code], # Country name, per ISO 3166
699
703
  CountryContinent[code], # Continent code.
700
- region_code, # Unfortunately this is called region_name in the City structure
704
+ region_code, # Unfortunately this is called region_name in the City structure
701
705
  lookup_region_name(CountryCode[code], region_code),
702
706
  (TimeZone["#{CountryCode[code]}#{region_code}"] || TimeZone["#{CountryCode[code]}"])
703
707
  )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clifford Heath
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-03 00:00:00.000000000 Z
12
+ date: 2017-01-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: |-
15
15
  GeoIP searches a GeoIP database for a given host or IP address, and