geoip 0.4.0 → 0.6.0
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/History.txt +4 -0
- data/License.txt +16 -0
- data/Manifest.txt +24 -0
- data/README.txt +10 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +71 -0
- data/config/requirements.rb +17 -0
- data/lib/geoip.rb +347 -106
- data/lib/geoip/version.rb +9 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_geoip.rb +11 -0
- data/test/test_helper.rb +2 -0
- data/website/index.html +106 -0
- data/website/index.txt +45 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +46 -17
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
This version Copyright (C) 2005-2007 Clifford Heath
|
2
|
+
Derived from the C version, Copyright (C) 2003 MaxMind LLC
|
3
|
+
|
4
|
+
This library is free software; you can redistribute it and/or
|
5
|
+
modify it under the terms of the GNU General Public
|
6
|
+
License as published by the Free Software Foundation; either
|
7
|
+
version 2.1 of the License, or (at your option) any later version.
|
8
|
+
|
9
|
+
This library is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public
|
15
|
+
License along with this library; if not, write to the Free Software
|
16
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
data/Manifest.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/geoip.rb
|
9
|
+
lib/geoip/version.rb
|
10
|
+
log/debug.log
|
11
|
+
script/destroy
|
12
|
+
script/generate
|
13
|
+
script/txt2html
|
14
|
+
setup.rb
|
15
|
+
tasks/deployment.rake
|
16
|
+
tasks/environment.rake
|
17
|
+
tasks/website.rake
|
18
|
+
test/test_geoip.rb
|
19
|
+
test/test_helper.rb
|
20
|
+
website/index.html
|
21
|
+
website/index.txt
|
22
|
+
website/javascripts/rounded_corners_lite.inc.js
|
23
|
+
website/stylesheets/screen.css
|
24
|
+
website/template.rhtml
|
data/README.txt
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
GeoIP searches a GeoIP database for a given host or IP address, and
|
2
|
+
returns information about the country where the IP address is allocated.
|
3
|
+
|
4
|
+
You need at least the free GeoIP.dat, for which the last known download
|
5
|
+
location is <http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz>
|
6
|
+
This API requires the file to be decompressed for searching. Other versions
|
7
|
+
of this database are available for purchase which contain more detailed
|
8
|
+
information, but this information is not returned by this implementation.
|
9
|
+
See www.maxmind.com for more information.
|
10
|
+
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'geoip/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Clifford Heath' # can also be an array of Authors
|
4
|
+
EMAIL = "cjheath@rubyforge.org"
|
5
|
+
DESCRIPTION = "description of gem"
|
6
|
+
GEM_NAME = 'geoip' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'geoip' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
12
|
+
@config = nil
|
13
|
+
RUBYFORGE_USERNAME = "unknown"
|
14
|
+
def rubyforge_username
|
15
|
+
unless @config
|
16
|
+
begin
|
17
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
18
|
+
rescue
|
19
|
+
puts <<-EOS
|
20
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
21
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
22
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
23
|
+
EOS
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
REV = nil
|
32
|
+
# UNCOMMENT IF REQUIRED:
|
33
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
34
|
+
VERS = Geoip::VERSION::STRING + (REV ? ".#{REV}" : "")
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'geoip documentation',
|
36
|
+
"--opname", "index.html",
|
37
|
+
"--line-numbers",
|
38
|
+
"--main", "README",
|
39
|
+
"--inline-source"]
|
40
|
+
|
41
|
+
class Hoe
|
42
|
+
def extra_deps
|
43
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
44
|
+
@extra_deps
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Generate all the Rake tasks
|
49
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
50
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
51
|
+
p.author = AUTHOR
|
52
|
+
p.description = DESCRIPTION
|
53
|
+
p.email = EMAIL
|
54
|
+
p.summary = DESCRIPTION
|
55
|
+
p.url = HOMEPATH
|
56
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
57
|
+
p.test_globs = ["test/**/test_*.rb"]
|
58
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
59
|
+
|
60
|
+
# == Optional
|
61
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
|
62
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
63
|
+
|
64
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
69
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
71
|
+
hoe.rsync_args = '-av --delete --ignore-errors'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
16
|
+
|
17
|
+
require 'geoip'
|
data/lib/geoip.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
1
2
|
#
|
2
3
|
# Native Ruby reader for the GeoIP database
|
3
4
|
# Lookup the country where IP address is allocated
|
@@ -46,24 +47,33 @@ require 'socket'
|
|
46
47
|
class GeoIP
|
47
48
|
private
|
48
49
|
CountryCode = [
|
49
|
-
"--","AP","EU","AD","AE","AF","AG","AI","AL","AM","AN",
|
50
|
-
"
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
56
|
-
"
|
57
|
-
"
|
58
|
-
"
|
59
|
-
"
|
60
|
-
"
|
61
|
-
"
|
62
|
-
"
|
63
|
-
"
|
64
|
-
"
|
65
|
-
"
|
66
|
-
"
|
50
|
+
"--","AP","EU","AD","AE","AF","AG","AI","AL","AM","AN",
|
51
|
+
"AO","AQ","AR","AS","AT","AU","AW","AZ","BA","BB",
|
52
|
+
"BD","BE","BF","BG","BH","BI","BJ","BM","BN","BO",
|
53
|
+
"BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD",
|
54
|
+
"CF","CG","CH","CI","CK","CL","CM","CN","CO","CR",
|
55
|
+
"CU","CV","CX","CY","CZ","DE","DJ","DK","DM","DO",
|
56
|
+
"DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ",
|
57
|
+
"FK","FM","FO","FR","FX","GA","GB","GD","GE","GF",
|
58
|
+
"GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT",
|
59
|
+
"GU","GW","GY","HK","HM","HN","HR","HT","HU","ID",
|
60
|
+
"IE","IL","IN","IO","IQ","IR","IS","IT","JM","JO",
|
61
|
+
"JP","KE","KG","KH","KI","KM","KN","KP","KR","KW",
|
62
|
+
"KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT",
|
63
|
+
"LU","LV","LY","MA","MC","MD","MG","MH","MK","ML",
|
64
|
+
"MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV",
|
65
|
+
"MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI",
|
66
|
+
"NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF",
|
67
|
+
"PG","PH","PK","PL","PM","PN","PR","PS","PT","PW",
|
68
|
+
"PY","QA","RE","RO","RU","RW","SA","SB","SC","SD",
|
69
|
+
"SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO",
|
70
|
+
"SR","ST","SV","SY","SZ","TC","TD","TF","TG","TH",
|
71
|
+
"TJ","TK","TM","TN","TO","TL","TR","TT","TV","TW",
|
72
|
+
"TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE",
|
73
|
+
"VG","VI","VN","VU","WF","WS","YE","YT","RS","ZA",
|
74
|
+
"ZM","ME","ZW","A1","A2","O1","AX","GG","IM","JE",
|
75
|
+
"BL","MF"
|
76
|
+
]
|
67
77
|
|
68
78
|
CountryCode3 = [
|
69
79
|
"--","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","ANT","AGO",
|
@@ -86,85 +96,294 @@ class GeoIP
|
|
86
96
|
"SYR","SWZ","TCA","TCD","TF","TGO","THA","TJK","TKL","TLS","TKM","TUN",
|
87
97
|
"TON","TUR","TTO","TUV","TWN","TZA","UKR","UGA","UM","USA","URY","UZB",
|
88
98
|
"VAT","VCT","VEN","VGB","VIR","VNM","VUT","WLF","WSM","YEM","YT","YUG",
|
89
|
-
"ZAF","ZMB","ZR","ZWE","A1","A2","O1"
|
99
|
+
"ZAF","ZMB","ZR","ZWE","A1","A2","O1"
|
100
|
+
]
|
90
101
|
|
91
102
|
CountryName = [
|
92
|
-
"N/A",
|
93
|
-
"
|
94
|
-
"
|
95
|
-
"
|
96
|
-
"
|
97
|
-
"
|
98
|
-
"
|
99
|
-
"
|
100
|
-
"
|
101
|
-
"
|
102
|
-
"
|
103
|
-
"
|
104
|
-
"
|
105
|
-
"
|
106
|
-
"
|
107
|
-
"
|
108
|
-
"
|
109
|
-
"
|
110
|
-
"
|
111
|
-
"
|
112
|
-
"
|
113
|
-
"
|
114
|
-
"
|
115
|
-
"
|
116
|
-
"
|
117
|
-
"
|
118
|
-
"
|
119
|
-
"
|
120
|
-
"
|
121
|
-
"
|
122
|
-
"
|
123
|
-
"
|
124
|
-
"
|
125
|
-
"
|
126
|
-
"
|
127
|
-
"
|
128
|
-
"
|
129
|
-
"
|
130
|
-
"
|
131
|
-
"
|
132
|
-
"
|
133
|
-
"
|
134
|
-
"
|
135
|
-
"
|
136
|
-
"
|
137
|
-
"
|
138
|
-
"
|
139
|
-
"
|
140
|
-
"
|
141
|
-
"
|
142
|
-
"
|
143
|
-
"
|
144
|
-
"
|
145
|
-
"
|
146
|
-
"
|
147
|
-
"
|
103
|
+
"N/A",
|
104
|
+
"Asia/Pacific Region",
|
105
|
+
"Europe",
|
106
|
+
"Andorra",
|
107
|
+
"United Arab Emirates",
|
108
|
+
"Afghanistan",
|
109
|
+
"Antigua and Barbuda",
|
110
|
+
"Anguilla",
|
111
|
+
"Albania",
|
112
|
+
"Armenia",
|
113
|
+
"Netherlands Antilles",
|
114
|
+
"Angola",
|
115
|
+
"Antarctica",
|
116
|
+
"Argentina",
|
117
|
+
"American Samoa",
|
118
|
+
"Austria",
|
119
|
+
"Australia",
|
120
|
+
"Aruba",
|
121
|
+
"Azerbaijan",
|
122
|
+
"Bosnia and Herzegovina",
|
123
|
+
"Barbados",
|
124
|
+
"Bangladesh",
|
125
|
+
"Belgium",
|
126
|
+
"Burkina Faso",
|
127
|
+
"Bulgaria",
|
128
|
+
"Bahrain",
|
129
|
+
"Burundi",
|
130
|
+
"Benin",
|
131
|
+
"Bermuda",
|
132
|
+
"Brunei Darussalam",
|
133
|
+
"Bolivia",
|
134
|
+
"Brazil",
|
135
|
+
"Bahamas",
|
136
|
+
"Bhutan",
|
137
|
+
"Bouvet Island",
|
138
|
+
"Botswana",
|
139
|
+
"Belarus",
|
140
|
+
"Belize",
|
141
|
+
"Canada",
|
142
|
+
"Cocos (Keeling) Islands",
|
143
|
+
"Congo, the Democratic Republic of the",
|
144
|
+
"Central African Republic",
|
145
|
+
"Congo",
|
146
|
+
"Switzerland",
|
147
|
+
"Cote D'Ivoire",
|
148
|
+
"Cook Islands",
|
149
|
+
"Chile",
|
150
|
+
"Cameroon",
|
151
|
+
"China",
|
152
|
+
"Colombia",
|
153
|
+
"Costa Rica",
|
154
|
+
"Cuba",
|
155
|
+
"Cape Verde",
|
156
|
+
"Christmas Island",
|
157
|
+
"Cyprus",
|
158
|
+
"Czech Republic",
|
159
|
+
"Germany",
|
160
|
+
"Djibouti",
|
161
|
+
"Denmark",
|
162
|
+
"Dominica",
|
163
|
+
"Dominican Republic",
|
164
|
+
"Algeria",
|
165
|
+
"Ecuador",
|
166
|
+
"Estonia",
|
167
|
+
"Egypt",
|
168
|
+
"Western Sahara",
|
169
|
+
"Eritrea",
|
170
|
+
"Spain",
|
171
|
+
"Ethiopia",
|
172
|
+
"Finland",
|
173
|
+
"Fiji",
|
174
|
+
"Falkland Islands (Malvinas)",
|
175
|
+
"Micronesia, Federated States of",
|
176
|
+
"Faroe Islands",
|
177
|
+
"France",
|
178
|
+
"France, Metropolitan",
|
179
|
+
"Gabon",
|
180
|
+
"United Kingdom",
|
181
|
+
"Grenada",
|
182
|
+
"Georgia",
|
183
|
+
"French Guiana",
|
184
|
+
"Ghana",
|
185
|
+
"Gibraltar",
|
186
|
+
"Greenland",
|
187
|
+
"Gambia",
|
188
|
+
"Guinea",
|
189
|
+
"Guadeloupe",
|
190
|
+
"Equatorial Guinea",
|
191
|
+
"Greece",
|
192
|
+
"South Georgia and the South Sandwich Islands",
|
193
|
+
"Guatemala",
|
194
|
+
"Guam",
|
195
|
+
"Guinea-Bissau",
|
196
|
+
"Guyana",
|
197
|
+
"Hong Kong",
|
198
|
+
"Heard Island and McDonald Islands",
|
199
|
+
"Honduras",
|
200
|
+
"Croatia",
|
201
|
+
"Haiti",
|
202
|
+
"Hungary",
|
203
|
+
"Indonesia",
|
204
|
+
"Ireland",
|
205
|
+
"Israel",
|
206
|
+
"India",
|
207
|
+
"British Indian Ocean Territory",
|
208
|
+
"Iraq",
|
209
|
+
"Iran, Islamic Republic of",
|
210
|
+
"Iceland",
|
211
|
+
"Italy",
|
212
|
+
"Jamaica",
|
213
|
+
"Jordan",
|
214
|
+
"Japan",
|
215
|
+
"Kenya",
|
216
|
+
"Kyrgyzstan",
|
217
|
+
"Cambodia",
|
218
|
+
"Kiribati",
|
219
|
+
"Comoros",
|
220
|
+
"Saint Kitts and Nevis",
|
221
|
+
"Korea, Democratic People's Republic of",
|
222
|
+
"Korea, Republic of",
|
223
|
+
"Kuwait",
|
224
|
+
"Cayman Islands",
|
225
|
+
"Kazakhstan",
|
226
|
+
"Lao People's Democratic Republic",
|
227
|
+
"Lebanon",
|
228
|
+
"Saint Lucia",
|
229
|
+
"Liechtenstein",
|
230
|
+
"Sri Lanka",
|
231
|
+
"Liberia",
|
232
|
+
"Lesotho",
|
233
|
+
"Lithuania",
|
234
|
+
"Luxembourg",
|
235
|
+
"Latvia",
|
236
|
+
"Libyan Arab Jamahiriya",
|
237
|
+
"Morocco",
|
238
|
+
"Monaco",
|
239
|
+
"Moldova, Republic of",
|
240
|
+
"Madagascar",
|
241
|
+
"Marshall Islands",
|
242
|
+
"Macedonia, the Former Yugoslav Republic of",
|
243
|
+
"Mali",
|
244
|
+
"Myanmar",
|
245
|
+
"Mongolia",
|
246
|
+
"Macau",
|
247
|
+
"Northern Mariana Islands",
|
248
|
+
"Martinique",
|
249
|
+
"Mauritania",
|
250
|
+
"Montserrat",
|
251
|
+
"Malta",
|
252
|
+
"Mauritius",
|
253
|
+
"Maldives",
|
254
|
+
"Malawi",
|
255
|
+
"Mexico",
|
256
|
+
"Malaysia",
|
257
|
+
"Mozambique",
|
258
|
+
"Namibia",
|
259
|
+
"New Caledonia",
|
260
|
+
"Niger",
|
261
|
+
"Norfolk Island",
|
262
|
+
"Nigeria",
|
263
|
+
"Nicaragua",
|
264
|
+
"Netherlands",
|
265
|
+
"Norway",
|
266
|
+
"Nepal",
|
267
|
+
"Nauru",
|
268
|
+
"Niue",
|
269
|
+
"New Zealand",
|
270
|
+
"Oman",
|
271
|
+
"Panama",
|
272
|
+
"Peru",
|
273
|
+
"French Polynesia",
|
274
|
+
"Papua New Guinea",
|
275
|
+
"Philippines",
|
276
|
+
"Pakistan",
|
277
|
+
"Poland",
|
278
|
+
"Saint Pierre and Miquelon",
|
279
|
+
"Pitcairn",
|
280
|
+
"Puerto Rico",
|
281
|
+
"Palestinian Territory, Occupied",
|
282
|
+
"Portugal",
|
283
|
+
"Palau",
|
284
|
+
"Paraguay",
|
285
|
+
"Qatar",
|
286
|
+
"Reunion",
|
287
|
+
"Romania",
|
288
|
+
"Russian Federation",
|
289
|
+
"Rwanda",
|
290
|
+
"Saudi Arabia",
|
291
|
+
"Solomon Islands",
|
292
|
+
"Seychelles",
|
293
|
+
"Sudan",
|
294
|
+
"Sweden",
|
295
|
+
"Singapore",
|
296
|
+
"Saint Helena",
|
297
|
+
"Slovenia",
|
298
|
+
"Svalbard and Jan Mayen",
|
299
|
+
"Slovakia",
|
300
|
+
"Sierra Leone",
|
301
|
+
"San Marino",
|
302
|
+
"Senegal",
|
303
|
+
"Somalia",
|
304
|
+
"Suriname",
|
305
|
+
"Sao Tome and Principe",
|
306
|
+
"El Salvador",
|
307
|
+
"Syrian Arab Republic",
|
308
|
+
"Swaziland",
|
309
|
+
"Turks and Caicos Islands",
|
310
|
+
"Chad",
|
311
|
+
"French Southern Territories",
|
312
|
+
"Togo",
|
313
|
+
"Thailand",
|
314
|
+
"Tajikistan",
|
315
|
+
"Tokelau",
|
316
|
+
"Turkmenistan",
|
317
|
+
"Tunisia",
|
318
|
+
"Tonga",
|
319
|
+
"Timor-Leste",
|
320
|
+
"Turkey",
|
321
|
+
"Trinidad and Tobago",
|
322
|
+
"Tuvalu",
|
323
|
+
"Taiwan, Province of China",
|
324
|
+
"Tanzania, United Republic of",
|
325
|
+
"Ukraine",
|
326
|
+
"Uganda",
|
327
|
+
"United States Minor Outlying Islands",
|
328
|
+
"United States",
|
329
|
+
"Uruguay",
|
330
|
+
"Uzbekistan",
|
331
|
+
"Holy See (Vatican City State)",
|
332
|
+
"Saint Vincent and the Grenadines",
|
333
|
+
"Venezuela",
|
334
|
+
"Virgin Islands, British",
|
335
|
+
"Virgin Islands, U.S.",
|
336
|
+
"Viet Nam",
|
337
|
+
"Vanuatu",
|
338
|
+
"Wallis and Futuna",
|
339
|
+
"Samoa",
|
340
|
+
"Yemen",
|
341
|
+
"Mayotte",
|
342
|
+
"Serbia",
|
343
|
+
"South Africa",
|
344
|
+
"Zambia",
|
345
|
+
"Montenegro",
|
346
|
+
"Zimbabwe",
|
347
|
+
"Anonymous Proxy",
|
348
|
+
"Satellite Provider",
|
349
|
+
"Other",
|
350
|
+
"Aland Islands",
|
351
|
+
"Guernsey",
|
352
|
+
"Isle of Man",
|
353
|
+
"Jersey",
|
354
|
+
"Saint Barthelemy",
|
355
|
+
"Saint Martin"
|
356
|
+
]
|
148
357
|
|
149
358
|
CountryContinent = [
|
150
|
-
"--","AS","EU","EU","AS","AS","SA","SA","EU","AS","SA",
|
151
|
-
"
|
152
|
-
"
|
153
|
-
"
|
154
|
-
"
|
155
|
-
"
|
156
|
-
"AF","
|
157
|
-
"SA","
|
158
|
-
"AF","
|
159
|
-
"
|
160
|
-
"
|
161
|
-
"
|
162
|
-
"SA","
|
163
|
-
"
|
164
|
-
"
|
165
|
-
"
|
166
|
-
"
|
167
|
-
"
|
359
|
+
"--","AS","EU","EU","AS","AS","SA","SA","EU","AS","SA",
|
360
|
+
"AF","AN","SA","OC","EU","OC","SA","AS","EU","SA",
|
361
|
+
"AS","EU","AF","EU","AS","AF","AF","SA","AS","SA",
|
362
|
+
"SA","SA","AS","AF","AF","EU","SA","NA","AS","AF",
|
363
|
+
"AF","AF","EU","AF","OC","SA","AF","AS","SA","SA",
|
364
|
+
"SA","AF","AS","AS","EU","EU","AF","EU","SA","SA",
|
365
|
+
"AF","SA","EU","AF","AF","AF","EU","AF","EU","OC",
|
366
|
+
"SA","OC","EU","EU","EU","AF","EU","SA","AS","SA",
|
367
|
+
"AF","EU","SA","AF","AF","SA","AF","EU","SA","SA",
|
368
|
+
"OC","AF","SA","AS","AF","SA","EU","SA","EU","AS",
|
369
|
+
"EU","AS","AS","AS","AS","AS","EU","EU","SA","AS",
|
370
|
+
"AS","AF","AS","AS","OC","AF","SA","AS","AS","AS",
|
371
|
+
"SA","AS","AS","AS","SA","EU","AS","AF","AF","EU",
|
372
|
+
"EU","EU","AF","AF","EU","EU","AF","OC","EU","AF",
|
373
|
+
"AS","AS","AS","OC","SA","AF","SA","EU","AF","AS",
|
374
|
+
"AF","NA","AS","AF","AF","OC","AF","OC","AF","SA",
|
375
|
+
"EU","EU","AS","OC","OC","OC","AS","SA","SA","OC",
|
376
|
+
"OC","AS","AS","EU","SA","OC","SA","AS","EU","OC",
|
377
|
+
"SA","AS","AF","EU","AS","AF","AS","OC","AF","AF",
|
378
|
+
"EU","AS","AF","EU","EU","EU","AF","EU","AF","AF",
|
379
|
+
"SA","AF","SA","AS","AF","SA","AF","AF","AF","AS",
|
380
|
+
"AS","OC","AS","AF","OC","AS","AS","SA","OC","AS",
|
381
|
+
"AF","EU","AF","OC","NA","SA","AS","EU","SA","SA",
|
382
|
+
"SA","SA","AS","OC","OC","OC","AS","AF","EU","AF",
|
383
|
+
"AF","EU","AF","--","--","--","EU","EU","EU","EU",
|
384
|
+
"SA","SA"
|
385
|
+
]
|
386
|
+
|
168
387
|
public
|
169
388
|
# Edition enumeration:
|
170
389
|
(GEOIP_COUNTRY_EDITION,
|
@@ -178,8 +397,8 @@ class GeoIP
|
|
178
397
|
GEOIP_ASNUM_EDITION,
|
179
398
|
GEOIP_NETSPEED_EDITION,
|
180
399
|
) = *1..10
|
181
|
-
private
|
182
400
|
|
401
|
+
private
|
183
402
|
COUNTRY_BEGIN = 16776960
|
184
403
|
STATE_BEGIN_REV0 = 16700000
|
185
404
|
STATE_BEGIN_REV1 = 16000000
|
@@ -248,7 +467,7 @@ class GeoIP
|
|
248
467
|
|
249
468
|
# Search the GeoIP database for the specified host, returning country info
|
250
469
|
#
|
251
|
-
# +hostname+ is a String holding the host's DNS name or numeric IP address
|
470
|
+
# +hostname+ is a String holding the host's DNS name or numeric IP address.
|
252
471
|
# Return an array of seven elements:
|
253
472
|
# * The host or IP address string as requested
|
254
473
|
# * The IP address string after looking up the host
|
@@ -290,7 +509,7 @@ class GeoIP
|
|
290
509
|
# Search the GeoIP database for the specified host, returning city info
|
291
510
|
#
|
292
511
|
# +hostname+ is a String holding the host's DNS name or numeric IP address
|
293
|
-
# Return an array of
|
512
|
+
# Return an array of twelve or fourteen elements:
|
294
513
|
# * All elements from the country query
|
295
514
|
# * The region (state or territory) name
|
296
515
|
# * The city name
|
@@ -298,7 +517,7 @@ class GeoIP
|
|
298
517
|
# * The latitude
|
299
518
|
# * The longitude
|
300
519
|
# * The dma_code and area_code, if available (REV1 City database)
|
301
|
-
private
|
520
|
+
private
|
302
521
|
|
303
522
|
def read_city(pos, hostname = '', ip = '')
|
304
523
|
@file.seek(pos + (2*@record_length-1) * @databaseSegments[0])
|
@@ -340,15 +559,15 @@ private
|
|
340
559
|
end
|
341
560
|
|
342
561
|
us_area_codes = []
|
343
|
-
if(record &&
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
562
|
+
if (record &&
|
563
|
+
record[0,3] &&
|
564
|
+
@databaseType == GEOIP_CITY_EDITION_REV1 &&
|
565
|
+
CountryCode[code] == "US") # UNTESTED
|
566
|
+
dmaarea_combo = le_to_ui(record[0,3].unpack('C*'))
|
567
|
+
dma_code = dmaarea_combo / 1000;
|
568
|
+
area_code = dmaarea_combo % 1000;
|
349
569
|
us_area_codes = [ dma_code, area_code ]
|
350
|
-
|
351
|
-
end
|
570
|
+
@iter_pos += 3 unless @iter_pos.nil?
|
352
571
|
end
|
353
572
|
|
354
573
|
[ hostname, # Requested hostname
|
@@ -364,7 +583,27 @@ private
|
|
364
583
|
longitude,
|
365
584
|
] + us_area_codes
|
366
585
|
end
|
367
|
-
|
586
|
+
|
587
|
+
public
|
588
|
+
|
589
|
+
# Search the GeoIP database for the specified host, returning city info.
|
590
|
+
#
|
591
|
+
# +hostname+ is a String holding the host's DNS name or numeric IP address.
|
592
|
+
# Return an array of twelve or fourteen elements:
|
593
|
+
# * The host or IP address string as requested
|
594
|
+
# * The IP address string after looking up the host
|
595
|
+
# * The GeoIP country-ID as an integer
|
596
|
+
# * The ISO3166-1 two-character country code
|
597
|
+
# * The ISO3166-2 three-character country code
|
598
|
+
# * The ISO3166 English-language name of the country
|
599
|
+
# * The two-character continent code
|
600
|
+
# * The region name
|
601
|
+
# * The city name
|
602
|
+
# * The postal code
|
603
|
+
# * The latitude
|
604
|
+
# * The longitude
|
605
|
+
# * The USA dma_code and area_code, if available (REV1 City database)
|
606
|
+
#
|
368
607
|
def city(hostname)
|
369
608
|
ip = hostname
|
370
609
|
if ip.kind_of?(String) && ip !~ /^[0-9.]*$/
|
@@ -382,6 +621,7 @@ public
|
|
382
621
|
read_city(pos, hostname, ip)
|
383
622
|
end
|
384
623
|
|
624
|
+
# Iterate through a GeoIP city database
|
385
625
|
def each
|
386
626
|
if (@databaseType != GEOIP_CITY_EDITION_REV0 &&
|
387
627
|
@databaseType != GEOIP_CITY_EDITION_REV1)
|
@@ -445,3 +685,4 @@ if $0 == __FILE__
|
|
445
685
|
p g.send(req, a)
|
446
686
|
}
|
447
687
|
end
|
688
|
+
|