geoip 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +10 -6
- data/Rakefile +2 -2
- data/geoip.gemspec +3 -3
- data/lib/geoip.rb +30 -16
- data/script/txt2html +4 -5
- data/website/index.txt +4 -4
- metadata +3 -3
data/README.rdoc
CHANGED
|
@@ -85,15 +85,19 @@ This version Copyright (C) 2005 Clifford Heath
|
|
|
85
85
|
Derived from the C version, Copyright (C) 2003 MaxMind LLC
|
|
86
86
|
|
|
87
87
|
This library is free software; you can redistribute it and/or
|
|
88
|
-
modify it under the terms of the GNU General Public
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
modify it under the terms of the GNU Lesser General Public License,
|
|
89
|
+
as published by the Free Software Foundation; either version 2.1 of
|
|
90
|
+
the License, or (at your option) any later version. This follows the
|
|
91
|
+
license applied by Maxmind to their C library, for example in the
|
|
92
|
+
version here:
|
|
93
|
+
<http://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.2.tar.gz>.
|
|
91
94
|
|
|
92
95
|
This library is distributed in the hope that it will be useful,
|
|
93
96
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
94
97
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
95
|
-
General Public License for more details.
|
|
98
|
+
Lesser General Public License for more details.
|
|
96
99
|
|
|
97
|
-
You should have received a copy of the GNU General Public
|
|
100
|
+
You should have received a copy of the GNU Lesser General Public
|
|
98
101
|
License along with this library; if not, write to the Free Software
|
|
99
|
-
Foundation, Inc.,
|
|
102
|
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
103
|
+
|
data/Rakefile
CHANGED
|
@@ -9,7 +9,7 @@ Jeweler::Tasks.new do |gem|
|
|
|
9
9
|
gem.name = "geoip"
|
|
10
10
|
gem.version = GeoIP::VERSION
|
|
11
11
|
gem.homepage = "http://github.com/cjheath/geoip"
|
|
12
|
-
gem.license = "
|
|
12
|
+
gem.license = "LGPL"
|
|
13
13
|
gem.summary = %Q{GeoIP searches a GeoIP database for a given host or IP address, and returns information about the country where the IP address is allocated, and the city, ISP and other information, if you have that database version.}
|
|
14
14
|
gem.description = %Q{GeoIP searches a GeoIP database for a given host or IP address, and
|
|
15
15
|
returns information about the country where the IP address is allocated,
|
|
@@ -31,7 +31,7 @@ Rake::TestTask.new(:test) do |test|
|
|
|
31
31
|
end
|
|
32
32
|
task :default => :test
|
|
33
33
|
|
|
34
|
-
require '
|
|
34
|
+
require 'rdoc/task'
|
|
35
35
|
Rake::RDocTask.new do |rdoc|
|
|
36
36
|
rdoc.rdoc_dir = 'rdoc'
|
|
37
37
|
rdoc.title = "geoip #{GeoIP::VERSION}"
|
data/geoip.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "geoip"
|
|
8
|
-
s.version = "1.2.
|
|
8
|
+
s.version = "1.2.2"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Clifford Heath", "Roland Moriz"]
|
|
12
|
-
s.date = "
|
|
12
|
+
s.date = "2013-08-05"
|
|
13
13
|
s.description = "GeoIP searches a GeoIP database for a given host or IP address, and\nreturns information about the country where the IP address is allocated,\nand the city, ISP and other information, if you have that database version."
|
|
14
14
|
s.email = ["clifford.heath@gmail.com", "rmoriz@gmail.com"]
|
|
15
15
|
s.executables = ["geoip"]
|
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
|
|
|
40
40
|
"website/template.rhtml"
|
|
41
41
|
]
|
|
42
42
|
s.homepage = "http://github.com/cjheath/geoip"
|
|
43
|
-
s.licenses = ["
|
|
43
|
+
s.licenses = ["LGPL"]
|
|
44
44
|
s.require_paths = ["lib"]
|
|
45
45
|
s.rubygems_version = "1.8.24"
|
|
46
46
|
s.summary = "GeoIP searches a GeoIP database for a given host or IP address, and returns information about the country where the IP address is allocated, and the city, ISP and other information, if you have that database version."
|
data/lib/geoip.rb
CHANGED
|
@@ -8,19 +8,18 @@
|
|
|
8
8
|
# Derived from the C version, Copyright (C) 2003 MaxMind LLC
|
|
9
9
|
#
|
|
10
10
|
# This library is free software; you can redistribute it and/or
|
|
11
|
-
# modify it under the terms of the GNU General Public
|
|
11
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
12
12
|
# License as published by the Free Software Foundation; either
|
|
13
13
|
# version 2.1 of the License, or (at your option) any later version.
|
|
14
14
|
#
|
|
15
15
|
# This library is distributed in the hope that it will be useful,
|
|
16
16
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
17
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18
|
-
# General Public License for more details.
|
|
18
|
+
# Lesser General Public License for more details.
|
|
19
19
|
#
|
|
20
|
-
# You should have received a copy of the GNU General Public
|
|
20
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
21
21
|
# License along with this library; if not, write to the Free Software
|
|
22
|
-
# Foundation, Inc.,
|
|
23
|
-
#
|
|
22
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
24
23
|
# = SYNOPSIS
|
|
25
24
|
#
|
|
26
25
|
# require 'geoip'
|
|
@@ -59,7 +58,7 @@ require 'yaml'
|
|
|
59
58
|
class GeoIP
|
|
60
59
|
|
|
61
60
|
# The GeoIP GEM version number
|
|
62
|
-
VERSION = "1.2.
|
|
61
|
+
VERSION = "1.2.2"
|
|
63
62
|
|
|
64
63
|
# The +data/+ directory for geoip
|
|
65
64
|
DATA_DIR = File.expand_path(File.join(File.dirname(__FILE__),'..','data','geoip'))
|
|
@@ -92,6 +91,7 @@ class GeoIP
|
|
|
92
91
|
GEOIP_PROXY_EDITION = 8
|
|
93
92
|
GEOIP_ASNUM_EDITION = 9
|
|
94
93
|
GEOIP_NETSPEED_EDITION = 10
|
|
94
|
+
GEOIP_COUNTRY_EDITION_V6 = 12
|
|
95
95
|
GEOIP_CITY_EDITION_REV1_V6 = 30
|
|
96
96
|
|
|
97
97
|
COUNTRY_BEGIN = 16776960 #:nodoc:
|
|
@@ -136,6 +136,9 @@ class GeoIP
|
|
|
136
136
|
# The Edition number that identifies which kind of database you've opened
|
|
137
137
|
attr_reader :database_type
|
|
138
138
|
|
|
139
|
+
# An IP that is used instead of local IPs
|
|
140
|
+
attr_accessor :local_ip_alias
|
|
141
|
+
|
|
139
142
|
alias databaseType database_type
|
|
140
143
|
|
|
141
144
|
# Open the GeoIP database and determine the file format version.
|
|
@@ -182,18 +185,20 @@ class GeoIP
|
|
|
182
185
|
return city(hostname)
|
|
183
186
|
end
|
|
184
187
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
@database_type
|
|
188
|
+
ip = lookup_ip(hostname)
|
|
189
|
+
if (@database_type == GEOIP_COUNTRY_EDITION ||
|
|
190
|
+
@database_type == GEOIP_PROXY_EDITION ||
|
|
191
|
+
@database_type == GEOIP_NETSPEED_EDITION)
|
|
192
|
+
# Convert numeric IP address to an integer
|
|
193
|
+
ipnum = iptonum(ip)
|
|
194
|
+
code = (seek_record(ipnum) - COUNTRY_BEGIN)
|
|
195
|
+
elsif @database_type == GEOIP_COUNTRY_EDITION_V6
|
|
196
|
+
ipaddr = IPAddr.new ip
|
|
197
|
+
code = (seek_record_v6(ipaddr.to_i) - COUNTRY_BEGIN)
|
|
198
|
+
else
|
|
188
199
|
throw "Invalid GeoIP database type, can't look up Country by IP"
|
|
189
200
|
end
|
|
190
201
|
|
|
191
|
-
ip = lookup_ip(hostname)
|
|
192
|
-
|
|
193
|
-
ipnum = iptonum(ip) # Convert numeric IP address to an integer
|
|
194
|
-
|
|
195
|
-
code = (seek_record(ipnum) - COUNTRY_BEGIN)
|
|
196
|
-
|
|
197
202
|
Country.new(
|
|
198
203
|
hostname, # Requested hostname
|
|
199
204
|
ip, # Ip address as dotted quad
|
|
@@ -393,6 +398,7 @@ class GeoIP
|
|
|
393
398
|
|
|
394
399
|
if (@database_type == GEOIP_COUNTRY_EDITION ||
|
|
395
400
|
@database_type == GEOIP_PROXY_EDITION ||
|
|
401
|
+
@database_type == GEOIP_COUNTRY_EDITION_V6 ||
|
|
396
402
|
@database_type == GEOIP_NETSPEED_EDITION)
|
|
397
403
|
@database_segments = [COUNTRY_BEGIN]
|
|
398
404
|
end
|
|
@@ -439,7 +445,7 @@ class GeoIP
|
|
|
439
445
|
|
|
440
446
|
# Get the postal code:
|
|
441
447
|
postal_code = spl[2]
|
|
442
|
-
@iter_pos += (postal_code.size + 1) unless @iter_pos.nil?
|
|
448
|
+
@iter_pos += (postal_code.size + 1) unless @iter_pos.nil? || postal_code.nil?
|
|
443
449
|
|
|
444
450
|
record = spl[3]
|
|
445
451
|
|
|
@@ -496,6 +502,10 @@ class GeoIP
|
|
|
496
502
|
end
|
|
497
503
|
|
|
498
504
|
def lookup_ip(ip_or_hostname) # :nodoc:
|
|
505
|
+
if is_local?(ip_or_hostname) && @local_ip_alias
|
|
506
|
+
ip_or_hostname = @local_ip_alias
|
|
507
|
+
end
|
|
508
|
+
|
|
499
509
|
if !ip_or_hostname.kind_of?(String) or ip_or_hostname =~ /^[0-9.]+$/
|
|
500
510
|
return ip_or_hostname
|
|
501
511
|
end
|
|
@@ -506,6 +516,10 @@ class GeoIP
|
|
|
506
516
|
ip
|
|
507
517
|
end
|
|
508
518
|
|
|
519
|
+
def is_local?(ip_or_hostname) #:nodoc:
|
|
520
|
+
["127.0.0.1", "localhost", "::1", "0000::1", "0:0:0:0:0:0:0:1"].include? ip_or_hostname
|
|
521
|
+
end
|
|
522
|
+
|
|
509
523
|
# Convert numeric IP address to Integer.
|
|
510
524
|
def iptonum(ip) #:nodoc:
|
|
511
525
|
if (ip.kind_of?(String) &&
|
data/script/txt2html
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require 'rubygems'
|
|
4
4
|
require 'redcloth'
|
|
5
|
-
require 'syntax/convertors/html'
|
|
6
5
|
require 'erb'
|
|
7
|
-
require File.dirname(__FILE__) + '/../lib/geoip.rb'
|
|
6
|
+
require './' + File.dirname(__FILE__) + '/../lib/geoip.rb'
|
|
8
7
|
|
|
9
8
|
version = GeoIP::VERSION
|
|
10
9
|
download = 'http://rubyforge.org/projects/geoip'
|
|
@@ -15,9 +14,9 @@ class Fixnum
|
|
|
15
14
|
return 'th' if (10..19).include?(self % 100)
|
|
16
15
|
# others
|
|
17
16
|
case self % 10
|
|
18
|
-
when 1
|
|
19
|
-
when 2
|
|
20
|
-
when 3
|
|
17
|
+
when 1; return 'st'
|
|
18
|
+
when 2; return 'nd'
|
|
19
|
+
when 3; return 'rd'
|
|
21
20
|
else return 'th'
|
|
22
21
|
end
|
|
23
22
|
end
|
data/website/index.txt
CHANGED
|
@@ -65,15 +65,15 @@ This version Copyright (C) 2005 Clifford Heath
|
|
|
65
65
|
Derived from the C version, Copyright (C) 2003 MaxMind LLC
|
|
66
66
|
|
|
67
67
|
This library is free software; you can redistribute it and/or
|
|
68
|
-
modify it under the terms of the GNU General Public
|
|
68
|
+
modify it under the terms of the GNU Lesser General Public
|
|
69
69
|
License as published by the Free Software Foundation; either
|
|
70
70
|
version 2.1 of the License, or (at your option) any later version.
|
|
71
71
|
|
|
72
72
|
This library is distributed in the hope that it will be useful,
|
|
73
73
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
74
74
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
75
|
-
General Public License for more details.
|
|
75
|
+
Lesser General Public License for more details.
|
|
76
76
|
|
|
77
|
-
You should have received a copy of the GNU General Public
|
|
77
|
+
You should have received a copy of the GNU Lesser General Public
|
|
78
78
|
License along with this library; if not, write to the Free Software
|
|
79
|
-
Foundation, Inc.,
|
|
79
|
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
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.2.
|
|
4
|
+
version: 1.2.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
description: ! 'GeoIP searches a GeoIP database for a given host or IP address, and
|
|
16
16
|
|
|
@@ -49,7 +49,7 @@ files:
|
|
|
49
49
|
- website/template.rhtml
|
|
50
50
|
homepage: http://github.com/cjheath/geoip
|
|
51
51
|
licenses:
|
|
52
|
-
-
|
|
52
|
+
- LGPL
|
|
53
53
|
post_install_message:
|
|
54
54
|
rdoc_options: []
|
|
55
55
|
require_paths:
|