geoip 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.txt +3 -1
- data/lib/geoip.rb +479 -448
- data/lib/geoip/version.rb +2 -2
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- data/website/index.html +1 -1
- metadata +46 -39
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -2,7 +2,9 @@ GeoIP searches a GeoIP database for a given host or IP address, and
|
|
2
2
|
returns information about the country where the IP address is allocated.
|
3
3
|
|
4
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
|
5
|
+
location is <http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz>,
|
6
|
+
or the city database from <http://www.maxmind.com/app/geolitecity>.
|
7
|
+
|
6
8
|
This API requires the file to be decompressed for searching. Other versions
|
7
9
|
of this database are available for purchase which contain more detailed
|
8
10
|
information, but this information is not returned by this implementation.
|
data/lib/geoip.rb
CHANGED
@@ -47,346 +47,346 @@ require 'socket'
|
|
47
47
|
class GeoIP
|
48
48
|
private
|
49
49
|
CountryCode = [
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
76
|
]
|
77
77
|
|
78
78
|
CountryCode3 = [
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
79
|
+
"--","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","ANT",
|
80
|
+
"AGO","AQ","ARG","ASM","AUT","AUS","ABW","AZE","BIH","BRB",
|
81
|
+
"BGD","BEL","BFA","BGR","BHR","BDI","BEN","BMU","BRN","BOL",
|
82
|
+
"BRA","BHS","BTN","BV","BWA","BLR","BLZ","CAN","CC","COD",
|
83
|
+
"CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI",
|
84
|
+
"CUB","CPV","CX","CYP","CZE","DEU","DJI","DNK","DMA","DOM",
|
85
|
+
"DZA","ECU","EST","EGY","ESH","ERI","ESP","ETH","FIN","FJI",
|
86
|
+
"FLK","FSM","FRO","FRA","FX","GAB","GBR","GRD","GEO","GUF",
|
87
|
+
"GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","GS","GTM",
|
88
|
+
"GUM","GNB","GUY","HKG","HM","HND","HRV","HTI","HUN","IDN",
|
89
|
+
"IRL","ISR","IND","IO","IRQ","IRN","ISL","ITA","JAM","JOR",
|
90
|
+
"JPN","KEN","KGZ","KHM","KIR","COM","KNA","PRK","KOR","KWT",
|
91
|
+
"CYM","KAZ","LAO","LBN","LCA","LIE","LKA","LBR","LSO","LTU",
|
92
|
+
"LUX","LVA","LBY","MAR","MCO","MDA","MDG","MHL","MKD","MLI",
|
93
|
+
"MMR","MNG","MAC","MNP","MTQ","MRT","MSR","MLT","MUS","MDV",
|
94
|
+
"MWI","MEX","MYS","MOZ","NAM","NCL","NER","NFK","NGA","NIC",
|
95
|
+
"NLD","NOR","NPL","NRU","NIU","NZL","OMN","PAN","PER","PYF",
|
96
|
+
"PNG","PHL","PAK","POL","SPM","PCN","PRI","PSE","PRT","PLW",
|
97
|
+
"PRY","QAT","REU","ROU","RUS","RWA","SAU","SLB","SYC","SDN",
|
98
|
+
"SWE","SGP","SHN","SVN","SJM","SVK","SLE","SMR","SEN","SOM",
|
99
|
+
"SUR","STP","SLV","SYR","SWZ","TCA","TCD","TF","TGO","THA",
|
100
|
+
"TJK","TKL","TKM","TUN","TON","TLS","TUR","TTO","TUV","TWN",
|
101
|
+
"TZA","UKR","UGA","UM","USA","URY","UZB","VAT","VCT","VEN",
|
102
|
+
"VGB","VIR","VNM","VUT","WLF","WSM","YEM","YT","SRB","ZAF",
|
103
|
+
"ZMB","MNE","ZWE","A1","A2","O1","ALA","GGY","IMN","JEY",
|
104
|
+
"BLM","MAF"
|
105
105
|
]
|
106
106
|
|
107
107
|
CountryName = [
|
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
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
108
|
+
"N/A",
|
109
|
+
"Asia/Pacific Region",
|
110
|
+
"Europe",
|
111
|
+
"Andorra",
|
112
|
+
"United Arab Emirates",
|
113
|
+
"Afghanistan",
|
114
|
+
"Antigua and Barbuda",
|
115
|
+
"Anguilla",
|
116
|
+
"Albania",
|
117
|
+
"Armenia",
|
118
|
+
"Netherlands Antilles",
|
119
|
+
"Angola",
|
120
|
+
"Antarctica",
|
121
|
+
"Argentina",
|
122
|
+
"American Samoa",
|
123
|
+
"Austria",
|
124
|
+
"Australia",
|
125
|
+
"Aruba",
|
126
|
+
"Azerbaijan",
|
127
|
+
"Bosnia and Herzegovina",
|
128
|
+
"Barbados",
|
129
|
+
"Bangladesh",
|
130
|
+
"Belgium",
|
131
|
+
"Burkina Faso",
|
132
|
+
"Bulgaria",
|
133
|
+
"Bahrain",
|
134
|
+
"Burundi",
|
135
|
+
"Benin",
|
136
|
+
"Bermuda",
|
137
|
+
"Brunei Darussalam",
|
138
|
+
"Bolivia",
|
139
|
+
"Brazil",
|
140
|
+
"Bahamas",
|
141
|
+
"Bhutan",
|
142
|
+
"Bouvet Island",
|
143
|
+
"Botswana",
|
144
|
+
"Belarus",
|
145
|
+
"Belize",
|
146
|
+
"Canada",
|
147
|
+
"Cocos (Keeling) Islands",
|
148
|
+
"Congo, the Democratic Republic of the",
|
149
|
+
"Central African Republic",
|
150
|
+
"Congo",
|
151
|
+
"Switzerland",
|
152
|
+
"Cote D'Ivoire",
|
153
|
+
"Cook Islands",
|
154
|
+
"Chile",
|
155
|
+
"Cameroon",
|
156
|
+
"China",
|
157
|
+
"Colombia",
|
158
|
+
"Costa Rica",
|
159
|
+
"Cuba",
|
160
|
+
"Cape Verde",
|
161
|
+
"Christmas Island",
|
162
|
+
"Cyprus",
|
163
|
+
"Czech Republic",
|
164
|
+
"Germany",
|
165
|
+
"Djibouti",
|
166
|
+
"Denmark",
|
167
|
+
"Dominica",
|
168
|
+
"Dominican Republic",
|
169
|
+
"Algeria",
|
170
|
+
"Ecuador",
|
171
|
+
"Estonia",
|
172
|
+
"Egypt",
|
173
|
+
"Western Sahara",
|
174
|
+
"Eritrea",
|
175
|
+
"Spain",
|
176
|
+
"Ethiopia",
|
177
|
+
"Finland",
|
178
|
+
"Fiji",
|
179
|
+
"Falkland Islands (Malvinas)",
|
180
|
+
"Micronesia, Federated States of",
|
181
|
+
"Faroe Islands",
|
182
|
+
"France",
|
183
|
+
"France, Metropolitan",
|
184
|
+
"Gabon",
|
185
|
+
"United Kingdom",
|
186
|
+
"Grenada",
|
187
|
+
"Georgia",
|
188
|
+
"French Guiana",
|
189
|
+
"Ghana",
|
190
|
+
"Gibraltar",
|
191
|
+
"Greenland",
|
192
|
+
"Gambia",
|
193
|
+
"Guinea",
|
194
|
+
"Guadeloupe",
|
195
|
+
"Equatorial Guinea",
|
196
|
+
"Greece",
|
197
|
+
"South Georgia and the South Sandwich Islands",
|
198
|
+
"Guatemala",
|
199
|
+
"Guam",
|
200
|
+
"Guinea-Bissau",
|
201
|
+
"Guyana",
|
202
|
+
"Hong Kong",
|
203
|
+
"Heard Island and McDonald Islands",
|
204
|
+
"Honduras",
|
205
|
+
"Croatia",
|
206
|
+
"Haiti",
|
207
|
+
"Hungary",
|
208
|
+
"Indonesia",
|
209
|
+
"Ireland",
|
210
|
+
"Israel",
|
211
|
+
"India",
|
212
|
+
"British Indian Ocean Territory",
|
213
|
+
"Iraq",
|
214
|
+
"Iran, Islamic Republic of",
|
215
|
+
"Iceland",
|
216
|
+
"Italy",
|
217
|
+
"Jamaica",
|
218
|
+
"Jordan",
|
219
|
+
"Japan",
|
220
|
+
"Kenya",
|
221
|
+
"Kyrgyzstan",
|
222
|
+
"Cambodia",
|
223
|
+
"Kiribati",
|
224
|
+
"Comoros",
|
225
|
+
"Saint Kitts and Nevis",
|
226
|
+
"Korea, Democratic People's Republic of",
|
227
|
+
"Korea, Republic of",
|
228
|
+
"Kuwait",
|
229
|
+
"Cayman Islands",
|
230
|
+
"Kazakhstan",
|
231
|
+
"Lao People's Democratic Republic",
|
232
|
+
"Lebanon",
|
233
|
+
"Saint Lucia",
|
234
|
+
"Liechtenstein",
|
235
|
+
"Sri Lanka",
|
236
|
+
"Liberia",
|
237
|
+
"Lesotho",
|
238
|
+
"Lithuania",
|
239
|
+
"Luxembourg",
|
240
|
+
"Latvia",
|
241
|
+
"Libyan Arab Jamahiriya",
|
242
|
+
"Morocco",
|
243
|
+
"Monaco",
|
244
|
+
"Moldova, Republic of",
|
245
|
+
"Madagascar",
|
246
|
+
"Marshall Islands",
|
247
|
+
"Macedonia, the Former Yugoslav Republic of",
|
248
|
+
"Mali",
|
249
|
+
"Myanmar",
|
250
|
+
"Mongolia",
|
251
|
+
"Macau",
|
252
|
+
"Northern Mariana Islands",
|
253
|
+
"Martinique",
|
254
|
+
"Mauritania",
|
255
|
+
"Montserrat",
|
256
|
+
"Malta",
|
257
|
+
"Mauritius",
|
258
|
+
"Maldives",
|
259
|
+
"Malawi",
|
260
|
+
"Mexico",
|
261
|
+
"Malaysia",
|
262
|
+
"Mozambique",
|
263
|
+
"Namibia",
|
264
|
+
"New Caledonia",
|
265
|
+
"Niger",
|
266
|
+
"Norfolk Island",
|
267
|
+
"Nigeria",
|
268
|
+
"Nicaragua",
|
269
|
+
"Netherlands",
|
270
|
+
"Norway",
|
271
|
+
"Nepal",
|
272
|
+
"Nauru",
|
273
|
+
"Niue",
|
274
|
+
"New Zealand",
|
275
|
+
"Oman",
|
276
|
+
"Panama",
|
277
|
+
"Peru",
|
278
|
+
"French Polynesia",
|
279
|
+
"Papua New Guinea",
|
280
|
+
"Philippines",
|
281
|
+
"Pakistan",
|
282
|
+
"Poland",
|
283
|
+
"Saint Pierre and Miquelon",
|
284
|
+
"Pitcairn",
|
285
|
+
"Puerto Rico",
|
286
|
+
"Palestinian Territory, Occupied",
|
287
|
+
"Portugal",
|
288
|
+
"Palau",
|
289
|
+
"Paraguay",
|
290
|
+
"Qatar",
|
291
|
+
"Reunion",
|
292
|
+
"Romania",
|
293
|
+
"Russian Federation",
|
294
|
+
"Rwanda",
|
295
|
+
"Saudi Arabia",
|
296
|
+
"Solomon Islands",
|
297
|
+
"Seychelles",
|
298
|
+
"Sudan",
|
299
|
+
"Sweden",
|
300
|
+
"Singapore",
|
301
|
+
"Saint Helena",
|
302
|
+
"Slovenia",
|
303
|
+
"Svalbard and Jan Mayen",
|
304
|
+
"Slovakia",
|
305
|
+
"Sierra Leone",
|
306
|
+
"San Marino",
|
307
|
+
"Senegal",
|
308
|
+
"Somalia",
|
309
|
+
"Suriname",
|
310
|
+
"Sao Tome and Principe",
|
311
|
+
"El Salvador",
|
312
|
+
"Syrian Arab Republic",
|
313
|
+
"Swaziland",
|
314
|
+
"Turks and Caicos Islands",
|
315
|
+
"Chad",
|
316
|
+
"French Southern Territories",
|
317
|
+
"Togo",
|
318
|
+
"Thailand",
|
319
|
+
"Tajikistan",
|
320
|
+
"Tokelau",
|
321
|
+
"Turkmenistan",
|
322
|
+
"Tunisia",
|
323
|
+
"Tonga",
|
324
|
+
"Timor-Leste",
|
325
|
+
"Turkey",
|
326
|
+
"Trinidad and Tobago",
|
327
|
+
"Tuvalu",
|
328
|
+
"Taiwan, Province of China",
|
329
|
+
"Tanzania, United Republic of",
|
330
|
+
"Ukraine",
|
331
|
+
"Uganda",
|
332
|
+
"United States Minor Outlying Islands",
|
333
|
+
"United States",
|
334
|
+
"Uruguay",
|
335
|
+
"Uzbekistan",
|
336
|
+
"Holy See (Vatican City State)",
|
337
|
+
"Saint Vincent and the Grenadines",
|
338
|
+
"Venezuela",
|
339
|
+
"Virgin Islands, British",
|
340
|
+
"Virgin Islands, U.S.",
|
341
|
+
"Viet Nam",
|
342
|
+
"Vanuatu",
|
343
|
+
"Wallis and Futuna",
|
344
|
+
"Samoa",
|
345
|
+
"Yemen",
|
346
|
+
"Mayotte",
|
347
|
+
"Serbia",
|
348
|
+
"South Africa",
|
349
|
+
"Zambia",
|
350
|
+
"Montenegro",
|
351
|
+
"Zimbabwe",
|
352
|
+
"Anonymous Proxy",
|
353
|
+
"Satellite Provider",
|
354
|
+
"Other",
|
355
|
+
"Aland Islands",
|
356
|
+
"Guernsey",
|
357
|
+
"Isle of Man",
|
358
|
+
"Jersey",
|
359
|
+
"Saint Barthelemy",
|
360
|
+
"Saint Martin"
|
361
361
|
]
|
362
362
|
|
363
363
|
CountryContinent = [
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
364
|
+
"--","AS","EU","EU","AS","AS","SA","SA","EU","AS","SA",
|
365
|
+
"AF","AN","SA","OC","EU","OC","SA","AS","EU","SA",
|
366
|
+
"AS","EU","AF","EU","AS","AF","AF","SA","AS","SA",
|
367
|
+
"SA","SA","AS","AF","AF","EU","SA","NA","AS","AF",
|
368
|
+
"AF","AF","EU","AF","OC","SA","AF","AS","SA","SA",
|
369
|
+
"SA","AF","AS","AS","EU","EU","AF","EU","SA","SA",
|
370
|
+
"AF","SA","EU","AF","AF","AF","EU","AF","EU","OC",
|
371
|
+
"SA","OC","EU","EU","EU","AF","EU","SA","AS","SA",
|
372
|
+
"AF","EU","SA","AF","AF","SA","AF","EU","SA","SA",
|
373
|
+
"OC","AF","SA","AS","AF","SA","EU","SA","EU","AS",
|
374
|
+
"EU","AS","AS","AS","AS","AS","EU","EU","SA","AS",
|
375
|
+
"AS","AF","AS","AS","OC","AF","SA","AS","AS","AS",
|
376
|
+
"SA","AS","AS","AS","SA","EU","AS","AF","AF","EU",
|
377
|
+
"EU","EU","AF","AF","EU","EU","AF","OC","EU","AF",
|
378
|
+
"AS","AS","AS","OC","SA","AF","SA","EU","AF","AS",
|
379
|
+
"AF","NA","AS","AF","AF","OC","AF","OC","AF","SA",
|
380
|
+
"EU","EU","AS","OC","OC","OC","AS","SA","SA","OC",
|
381
|
+
"OC","AS","AS","EU","SA","OC","SA","AS","EU","OC",
|
382
|
+
"SA","AS","AF","EU","AS","AF","AS","OC","AF","AF",
|
383
|
+
"EU","AS","AF","EU","EU","EU","AF","EU","AF","AF",
|
384
|
+
"SA","AF","SA","AS","AF","SA","AF","AF","AF","AS",
|
385
|
+
"AS","OC","AS","AF","OC","AS","AS","SA","OC","AS",
|
386
|
+
"AF","EU","AF","OC","NA","SA","AS","EU","SA","SA",
|
387
|
+
"SA","SA","AS","OC","OC","OC","AS","AF","EU","AF",
|
388
|
+
"AF","EU","AF","--","--","--","EU","EU","EU","EU",
|
389
|
+
"SA","SA"
|
390
390
|
]
|
391
391
|
|
392
392
|
public
|
@@ -426,48 +426,48 @@ class GeoIP
|
|
426
426
|
# +filename+ is a String holding the path to the GeoIP.dat file
|
427
427
|
# +options+ is an integer holding caching flags (unimplemented)
|
428
428
|
def initialize(filename, flags = 0)
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
429
|
+
@flags = flags
|
430
|
+
@databaseType = GEOIP_COUNTRY_EDITION
|
431
|
+
@record_length = STANDARD_RECORD_LENGTH
|
432
|
+
@file = File.open(filename, 'rb')
|
433
|
+
@file.seek(-3, IO::SEEK_END)
|
434
|
+
0.upto(STRUCTURE_INFO_MAX_SIZE-1) { |i|
|
435
|
+
if @file.read(3) == "\xFF\xFF\xFF"
|
436
|
+
@databaseType = @file.getc
|
437
|
+
@databaseType -= 105 if @databaseType >= 106
|
438
|
+
|
439
|
+
if (@databaseType == GEOIP_REGION_EDITION_REV0)
|
440
|
+
# Region Edition, pre June 2003
|
441
|
+
@databaseSegments = [ STATE_BEGIN_REV0 ]
|
442
|
+
elsif (@databaseType == GEOIP_REGION_EDITION_REV1)
|
443
|
+
# Region Edition, post June 2003
|
444
|
+
@databaseSegments = [ STATE_BEGIN_REV1 ]
|
445
|
+
elsif (@databaseType == GEOIP_CITY_EDITION_REV0 ||
|
446
|
+
@databaseType == GEOIP_CITY_EDITION_REV1 ||
|
447
|
+
@databaseType == GEOIP_ORG_EDITION ||
|
448
|
+
@databaseType == GEOIP_ISP_EDITION ||
|
449
|
+
@databaseType == GEOIP_ASNUM_EDITION)
|
450
|
+
# City/Org Editions have two segments, read offset of second segment
|
451
|
+
@databaseSegments = [ 0 ]
|
452
|
+
sr = @file.read(3).unpack("C*")
|
453
|
+
@databaseSegments[0] += le_to_ui(sr)
|
454
|
+
|
455
|
+
if (@databaseType == GEOIP_ORG_EDITION ||
|
456
|
+
@databaseType == GEOIP_ISP_EDITION)
|
457
|
+
@record_length = 4
|
458
|
+
end
|
459
|
+
end
|
460
|
+
break
|
461
|
+
|
462
|
+
else
|
463
|
+
@file.seek(-4, IO::SEEK_CUR)
|
464
|
+
end
|
465
|
+
}
|
466
|
+
if (@databaseType == GEOIP_COUNTRY_EDITION ||
|
467
|
+
@databaseType == GEOIP_PROXY_EDITION ||
|
468
|
+
@databaseType == GEOIP_NETSPEED_EDITION)
|
469
|
+
@databaseSegments = [ COUNTRY_BEGIN ]
|
470
|
+
end
|
471
471
|
end
|
472
472
|
|
473
473
|
# Search the GeoIP database for the specified host, returning country info
|
@@ -483,32 +483,32 @@ class GeoIP
|
|
483
483
|
# * The two-character continent code
|
484
484
|
#
|
485
485
|
def country(hostname)
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
486
|
+
if (@databaseType == GEOIP_CITY_EDITION_REV0 ||
|
487
|
+
@databaseType == GEOIP_CITY_EDITION_REV1)
|
488
|
+
return city(hostname)
|
489
|
+
end
|
490
|
+
|
491
|
+
ip = hostname
|
492
|
+
if ip.kind_of?(String) && ip !~ /^[0-9.]*$/
|
493
|
+
# Lookup IP address, we were given a name
|
494
|
+
ip = IPSocket.getaddress(hostname)
|
495
|
+
end
|
496
|
+
|
497
|
+
# Convert numeric IP address to an integer
|
498
|
+
ipnum = iptonum(ip)
|
499
|
+
if (@databaseType != GEOIP_COUNTRY_EDITION &&
|
500
|
+
@databaseType != GEOIP_PROXY_EDITION &&
|
501
|
+
@databaseType != GEOIP_NETSPEED_EDITION)
|
502
|
+
throw "Invalid GeoIP database type, can't look up Country by IP"
|
503
|
+
end
|
504
|
+
code = seek_record(ipnum) - COUNTRY_BEGIN;
|
505
|
+
[ hostname, # Requested hostname
|
506
|
+
ip, # Ip address as dotted quad
|
507
|
+
code, # GeoIP's country code
|
508
|
+
CountryCode[code], # ISO3166-1 code
|
509
|
+
CountryCode3[code], # ISO3166-2 code
|
510
|
+
CountryName[code], # Country name, per IS03166
|
511
|
+
CountryContinent[code] ] # Continent code.
|
512
512
|
end
|
513
513
|
|
514
514
|
# Search the GeoIP database for the specified host, returning city info
|
@@ -525,29 +525,29 @@ class GeoIP
|
|
525
525
|
private
|
526
526
|
|
527
527
|
def read_city(pos, hostname = '', ip = '')
|
528
|
-
|
528
|
+
@file.seek(pos + (2*@record_length-1) * @databaseSegments[0])
|
529
529
|
return nil if((record = @file.read(FULL_RECORD_LENGTH)).nil?)
|
530
530
|
|
531
|
-
|
532
|
-
|
533
|
-
|
531
|
+
# The country code is the first byte:
|
532
|
+
code = record[0]
|
533
|
+
record = record[1..-1]
|
534
534
|
@iter_pos += 1 unless @iter_pos.nil?
|
535
535
|
|
536
536
|
spl = record.split("\x00", 4)
|
537
|
-
|
537
|
+
# Get the region:
|
538
538
|
region = spl[0]
|
539
539
|
@iter_pos += (region.size + 1) unless @iter_pos.nil?
|
540
540
|
|
541
|
-
|
541
|
+
# Get the city:
|
542
542
|
city = spl[1]
|
543
543
|
@iter_pos += (city.size + 1) unless @iter_pos.nil?
|
544
544
|
|
545
|
-
|
545
|
+
# Get the postal code:
|
546
546
|
postal_code = spl[2]
|
547
547
|
@iter_pos += (postal_code.size + 1) unless @iter_pos.nil?
|
548
548
|
|
549
549
|
record = spl[3]
|
550
|
-
|
550
|
+
# Get the latitude/longitude:
|
551
551
|
if(record && record[0,3]) then
|
552
552
|
latitude = le_to_ui(record[0,3].unpack('C*')) / 10000.0 - 180
|
553
553
|
record = record[3..-1]
|
@@ -563,30 +563,30 @@ class GeoIP
|
|
563
563
|
longitude = ''
|
564
564
|
end
|
565
565
|
|
566
|
-
|
566
|
+
us_area_codes = []
|
567
567
|
if (record &&
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
568
|
+
record[0,3] &&
|
569
|
+
@databaseType == GEOIP_CITY_EDITION_REV1 &&
|
570
|
+
CountryCode[code] == "US") # UNTESTED
|
571
|
+
dmaarea_combo = le_to_ui(record[0,3].unpack('C*'))
|
572
|
+
dma_code = dmaarea_combo / 1000;
|
573
|
+
area_code = dmaarea_combo % 1000;
|
574
|
+
us_area_codes = [ dma_code, area_code ]
|
575
|
+
@iter_pos += 3 unless @iter_pos.nil?
|
576
|
+
end
|
577
|
+
|
578
|
+
[ hostname, # Requested hostname
|
579
|
+
ip, # Ip address as dotted quad
|
580
|
+
CountryCode[code], # ISO3166-1 code
|
581
|
+
CountryCode3[code], # ISO3166-2 code
|
582
|
+
CountryName[code], # Country name, per IS03166
|
583
|
+
CountryContinent[code], # Continent code.
|
584
|
+
region, # Region name
|
585
|
+
city, # City name
|
586
|
+
postal_code, # Postal code
|
587
|
+
latitude,
|
588
|
+
longitude,
|
589
|
+
] + us_area_codes
|
590
590
|
end
|
591
591
|
|
592
592
|
public
|
@@ -626,6 +626,37 @@ class GeoIP
|
|
626
626
|
read_city(pos, hostname, ip)
|
627
627
|
end
|
628
628
|
|
629
|
+
# Search a ISP GeoIP database for the specified host, returning the ISP
|
630
|
+
#
|
631
|
+
# +hostname+ is a String holding the host's DNS name or numeric IP address.
|
632
|
+
# Return the ISP name
|
633
|
+
#
|
634
|
+
def isp(hostname)
|
635
|
+
ip = hostname
|
636
|
+
if ip.kind_of?(String) && ip !~ /^[0-9.]*$/
|
637
|
+
# Lookup IP address, we were given a name
|
638
|
+
ip = IPSocket.getaddress(hostname)
|
639
|
+
end
|
640
|
+
|
641
|
+
# Convert numeric IP address to an integer
|
642
|
+
ipnum = iptonum(ip)
|
643
|
+
if @databaseType != GEOIP_ISP_EDITION then
|
644
|
+
throw "Invalid GeoIP database type, can't look up Organization/ISP by IP"
|
645
|
+
end
|
646
|
+
pos = seek_record(ipnum);
|
647
|
+
@file.seek(pos + (2*@record_length-1) * @databaseSegments[0])
|
648
|
+
record = @file.read(MAX_ORG_RECORD_LENGTH)
|
649
|
+
record = record.sub(/\000.*/, '')
|
650
|
+
record
|
651
|
+
end
|
652
|
+
|
653
|
+
# Search a ISP GeoIP database for the specified host, returning the organization
|
654
|
+
#
|
655
|
+
# +hostname+ is a String holding the host's DNS name or numeric IP address.
|
656
|
+
# Return the organization associated with it
|
657
|
+
#
|
658
|
+
alias_method(:organization, :isp) # Untested, according to Maxmind docs this should work
|
659
|
+
|
629
660
|
# Iterate through a GeoIP city database
|
630
661
|
def each
|
631
662
|
if (@databaseType != GEOIP_CITY_EDITION_REV0 &&
|
@@ -644,39 +675,39 @@ class GeoIP
|
|
644
675
|
end
|
645
676
|
|
646
677
|
private
|
647
|
-
def iptonum(ip)
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
678
|
+
def iptonum(ip) # Convert numeric IP address to integer
|
679
|
+
if ip.kind_of?(String) &&
|
680
|
+
ip =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/
|
681
|
+
ip = be_to_ui(Regexp.last_match().to_a.slice(1..4))
|
682
|
+
end
|
683
|
+
ip
|
653
684
|
end
|
654
685
|
|
655
686
|
def seek_record(ipnum)
|
656
|
-
|
657
|
-
|
658
|
-
|
687
|
+
# Binary search in the file.
|
688
|
+
# Records are pairs of little-endian integers, each of @record_length.
|
689
|
+
offset = 0
|
659
690
|
mask = 0x80000000
|
660
|
-
|
661
|
-
|
691
|
+
31.downto(0) { |depth|
|
692
|
+
@file.seek(@record_length * 2 * offset);
|
662
693
|
buf = @file.read(@record_length * 2);
|
663
|
-
|
664
|
-
|
665
|
-
|
694
|
+
buf.slice!(0...@record_length) if ((ipnum & mask) != 0)
|
695
|
+
offset = le_to_ui(buf[0...@record_length].unpack("C*"))
|
696
|
+
return offset if (offset >= @databaseSegments[0])
|
666
697
|
mask >>= 1
|
667
|
-
|
698
|
+
}
|
668
699
|
end
|
669
700
|
|
670
701
|
# Convert a big-endian array of numeric bytes to unsigned int
|
671
702
|
def be_to_ui(s)
|
672
|
-
|
703
|
+
s.inject(0) { |m, o|
|
673
704
|
(m << 8) + o.to_i
|
674
|
-
|
705
|
+
}
|
675
706
|
end
|
676
707
|
|
677
708
|
# Same for little-endian
|
678
709
|
def le_to_ui(s)
|
679
|
-
|
710
|
+
be_to_ui(s.reverse)
|
680
711
|
end
|
681
712
|
end
|
682
713
|
|
data/lib/geoip/version.rb
CHANGED
data/script/destroy
CHANGED
File without changes
|
data/script/generate
CHANGED
File without changes
|
data/script/txt2html
CHANGED
File without changes
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>geoip</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/geoip"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/geoip" class="numbers">0.
|
36
|
+
<a href="http://rubyforge.org/projects/geoip" class="numbers">0.7.0</a>
|
37
37
|
</div>
|
38
38
|
<h2>→ ‘Geographic info for an IP address’</h2>
|
39
39
|
|
metadata
CHANGED
@@ -1,33 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: geoip
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2008-03-11 00:00:00 +11:00
|
8
|
-
summary: description of gem
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: cjheath@rubyforge.org
|
12
|
-
homepage: http://geoip.rubyforge.org
|
13
|
-
rubyforge_project: geoip
|
14
|
-
description: description of gem
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.7.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Clifford Heath
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-03 00:00:00 +10:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: description of gem
|
17
|
+
email: cjheath@rubyforge.org
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- History.txt
|
24
|
+
- License.txt
|
25
|
+
- Manifest.txt
|
26
|
+
- README.txt
|
27
|
+
- website/index.txt
|
31
28
|
files:
|
32
29
|
- History.txt
|
33
30
|
- License.txt
|
@@ -53,23 +50,33 @@ files:
|
|
53
50
|
- website/javascripts/rounded_corners_lite.inc.js
|
54
51
|
- website/stylesheets/screen.css
|
55
52
|
- website/template.rhtml
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://geoip.rubyforge.org
|
55
|
+
post_install_message:
|
59
56
|
rdoc_options:
|
60
57
|
- --main
|
61
58
|
- README.txt
|
62
|
-
|
63
|
-
-
|
64
|
-
|
65
|
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
72
73
|
requirements: []
|
73
74
|
|
74
|
-
|
75
|
-
|
75
|
+
rubyforge_project: geoip
|
76
|
+
rubygems_version: 1.1.0
|
77
|
+
signing_key:
|
78
|
+
specification_version: 2
|
79
|
+
summary: description of gem
|
80
|
+
test_files:
|
81
|
+
- test/test_geoip.rb
|
82
|
+
- test/test_helper.rb
|