geoip 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.5.0 2007-10-24
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
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
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
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","AO","AQ","AR",
50
- "AS","AT","AU","AW","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ",
51
- "BM","BN","BO","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF",
52
- "CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CX","CY","CZ",
53
- "DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI",
54
- "FJ","FK","FM","FO","FR","FX","GA","GB","GD","GE","GF","GH","GI","GL",
55
- "GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR",
56
- "HT","HU","ID","IE","IL","IN","IO","IQ","IR","IS","IT","JM","JO","JP",
57
- "KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC",
58
- "LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","MG","MH","MK",
59
- "ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY",
60
- "MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM",
61
- "PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY",
62
- "QA","RE","RO","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ",
63
- "SK","SL","SM","SN","SO","SR","ST","SV","SY","SZ","TC","TD","TF","TG",
64
- "TH","TJ","TK","TM","TN","TO","TP","TR","TT","TV","TW","TZ","UA","UG",
65
- "UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE",
66
- "YT","YU","ZA","ZM","ZR","ZW","A1","A2","O1" ]
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","Asia/Pacific Region","Europe","Andorra","United Arab Emirates",
93
- "Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia",
94
- "Netherlands Antilles","Angola","Antarctica","Argentina",
95
- "American Samoa","Austria","Australia","Aruba","Azerbaijan",
96
- "Bosnia and Herzegovina","Barbados","Bangladesh","Belgium",
97
- "Burkina Faso","Bulgaria","Bahrain","Burundi","Benin","Bermuda",
98
- "Brunei Darussalam","Bolivia","Brazil","Bahamas","Bhutan",
99
- "Bouvet Island","Botswana","Belarus","Belize","Canada",
100
- "Cocos (Keeling) Islands","Congo, The Democratic Republic of the",
101
- "Central African Republic","Congo","Switzerland","Cote D'Ivoire",
102
- "Cook Islands","Chile","Cameroon","China","Colombia","Costa Rica",
103
- "Cuba","Cape Verde","Christmas Island","Cyprus","Czech Republic",
104
- "Germany","Djibouti","Denmark","Dominica","Dominican Republic",
105
- "Algeria","Ecuador","Estonia","Egypt","Western Sahara","Eritrea",
106
- "Spain","Ethiopia","Finland","Fiji","Falkland Islands (Malvinas)",
107
- "Micronesia, Federated States of","Faroe Islands","France",
108
- "France, Metropolitan","Gabon","United Kingdom","Grenada","Georgia",
109
- "French Guiana","Ghana","Gibraltar","Greenland","Gambia","Guinea",
110
- "Guadeloupe","Equatorial Guinea","Greece",
111
- "South Georgia and the South Sandwich Islands","Guatemala","Guam",
112
- "Guinea-Bissau","Guyana","Hong Kong",
113
- "Heard Island and McDonald Islands","Honduras","Croatia","Haiti",
114
- "Hungary","Indonesia","Ireland","Israel","India",
115
- "British Indian Ocean Territory","Iraq","Iran, Islamic Republic of",
116
- "Iceland","Italy","Jamaica","Jordan","Japan","Kenya","Kyrgyzstan",
117
- "Cambodia","Kiribati","Comoros","Saint Kitts and Nevis",
118
- "Korea, Democratic People's Republic of","Korea, Republic of","Kuwait",
119
- "Cayman Islands","Kazakhstan","Lao People's Democratic Republic",
120
- "Lebanon","Saint Lucia","Liechtenstein","Sri Lanka","Liberia","Lesotho",
121
- "Lithuania","Luxembourg","Latvia","Libyan Arab Jamahiriya","Morocco",
122
- "Monaco","Moldova, Republic of","Madagascar","Marshall Islands",
123
- "Macedonia","Mali","Myanmar","Mongolia","Macau",
124
- "Northern Mariana Islands","Martinique","Mauritania","Montserrat",
125
- "Malta","Mauritius","Maldives","Malawi","Mexico","Malaysia",
126
- "Mozambique","Namibia","New Caledonia","Niger","Norfolk Island",
127
- "Nigeria","Nicaragua","Netherlands","Norway","Nepal","Nauru","Niue",
128
- "New Zealand","Oman","Panama","Peru","French Polynesia",
129
- "Papua New Guinea","Philippines","Pakistan","Poland",
130
- "Saint Pierre and Miquelon","Pitcairn Islands","Puerto Rico",
131
- "Palestinian Territory, Occupied","Portugal","Palau","Paraguay","Qatar",
132
- "Reunion","Romania","Russian Federation","Rwanda","Saudi Arabia",
133
- "Solomon Islands","Seychelles","Sudan","Sweden","Singapore",
134
- "Saint Helena","Slovenia","Svalbard and Jan Mayen","Slovakia",
135
- "Sierra Leone","San Marino","Senegal","Somalia","Suriname",
136
- "Sao Tome and Principe","El Salvador","Syrian Arab Republic",
137
- "Swaziland","Turks and Caicos Islands","Chad",
138
- "French Southern Territories","Togo","Thailand","Tajikistan","Tokelau",
139
- "Turkmenistan","Tunisia","Tonga","East Timor","Turkey",
140
- "Trinidad and Tobago","Tuvalu","Taiwan","Tanzania, United Republic of",
141
- "Ukraine","Uganda","United States Minor Outlying Islands",
142
- "United States","Uruguay","Uzbekistan","Holy See (Vatican City State)",
143
- "Saint Vincent and the Grenadines","Venezuela",
144
- "Virgin Islands, British","Virgin Islands, U.S.","Vietnam","Vanuatu",
145
- "Wallis and Futuna", "Samoa","Yemen","Mayotte","Yugoslavia",
146
- "South Africa","Zambia","Zaire", "Zimbabwe","Anonymous Proxy",
147
- "Satellite Provider","Other"]
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","AF","AN","SA",
151
- "OC","EU","OC","SA","AS","EU","SA","AS","EU","AF","EU","AS","AF","AF",
152
- "SA","AS","SA","SA","SA","AS","AF","AF","EU","SA","NA","AS","AF","AF",
153
- "AF","EU","AF","OC","SA","AF","AS","SA","SA","SA","AF","AS","AS","EU",
154
- "EU","AF","EU","SA","SA","AF","SA","EU","AF","AF","AF","EU","AF","EU",
155
- "OC","SA","OC","EU","EU","EU","AF","EU","SA","AS","SA","AF","EU","SA",
156
- "AF","AF","SA","AF","EU","SA","SA","OC","AF","SA","AS","AF","SA","EU",
157
- "SA","EU","AS","EU","AS","AS","AS","AS","AS","EU","EU","SA","AS","AS",
158
- "AF","AS","AS","OC","AF","SA","AS","AS","AS","SA","AS","AS","AS","SA",
159
- "EU","AS","AF","AF","EU","EU","EU","AF","AF","EU","EU","AF","OC","EU",
160
- "AF","AS","AS","AS","OC","SA","AF","SA","EU","AF","AS","AF","NA","AS",
161
- "AF","AF","OC","AF","OC","AF","SA","EU","EU","AS","OC","OC","OC","AS",
162
- "SA","SA","OC","OC","AS","AS","EU","SA","OC","SA","AS","EU","OC","SA",
163
- "AS","AF","EU","AS","AF","AS","OC","AF","AF","EU","AS","AF","EU","EU",
164
- "EU","AF","EU","AF","AF","SA","AF","SA","AS","AF","SA","AF","AF","AF",
165
- "AS","AS","OC","AS","AF","OC","AS","AS","SA","OC","AS","AF","EU","AF",
166
- "OC","NA","SA","AS","EU","SA","SA","SA","SA","AS","OC","OC","OC","AS",
167
- "AF","EU","AF","AF","AF","AF"]
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 eleven or thirteen elements:
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 && record[0,3]) then
344
- if (@databaseType == GEOIP_CITY_EDITION_REV1 &&
345
- CountryCode[code] == "US") # UNTESTED
346
- dmaarea_combo = le_to_ui(record[0,3].unpack('C*'))
347
- dma_code = dmaarea_combo / 1000;
348
- area_code = dmaarea_combo % 1000;
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
- @iter_pos += 3 unless @iter_pos.nil?
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
- public
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
+