geoip 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/geoip.rb +84 -80
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3520d7b15c106de43cc9c269bcec4cb371016f9
|
4
|
+
data.tar.gz: 0e88256388fb9550337811db7662a8c3bec6a57d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f583b543af13df3e630880c81be10f7a958e2fcd91aab4d7b1842b6322104c35bd60abb9c124b03fb8202a55ee0c5817505890dd22d5f633fe420a097aab6393
|
7
|
+
data.tar.gz: 3a32e4572920f66b226ec59f9fd997271d6ba92faadc08fbcd3b12a6eb62c412610fd1a4427766582e2c14abc15b0c8911d5e9e8377b1c2b291115ee6964e391
|
data/lib/geoip.rb
CHANGED
@@ -58,7 +58,7 @@ require 'yaml'
|
|
58
58
|
class GeoIP
|
59
59
|
|
60
60
|
# The GeoIP GEM version number
|
61
|
-
VERSION = "1.6.
|
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
|
-
|
276
|
-
|
276
|
+
ipaddr = IPAddr.new ip
|
277
|
+
code = (seek_record(ipaddr.to_i) - COUNTRY_BEGIN)
|
277
278
|
else
|
278
|
-
|
279
|
-
|
280
|
-
|
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
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
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
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
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
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
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
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
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
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
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
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
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,
|
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.
|
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:
|
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
|