adept_geoip 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +16 -0
- data/README.rdoc +90 -0
- data/Rakefile +58 -0
- data/adept_geoip.gemspec +60 -0
- data/bin/geoip +23 -0
- data/config/website.yml +2 -0
- data/data/geoip/country_code.yml +255 -0
- data/data/geoip/country_code3.yml +255 -0
- data/data/geoip/country_continent.yml +255 -0
- data/data/geoip/country_name.yml +255 -0
- data/data/geoip/time_zone.yml +677 -0
- data/geoip.gemspec +57 -0
- data/lib/geoip.rb +563 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +67 -0
- data/test/test_geoip.rb +11 -0
- data/test/test_helper.rb +3 -0
- data/website/index.txt +79 -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 +78 -0
data/History.rdoc
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
== 0.8.1 2009-06-04
|
2
|
+
|
3
|
+
* Added GeoIP#close method to close the file descriptor
|
4
|
+
|
5
|
+
== 0.8.0 2008-08-29
|
6
|
+
|
7
|
+
* Added Mutex protection around file I/O for thread safety
|
8
|
+
|
9
|
+
== 0.7.0 2008-05-03
|
10
|
+
|
11
|
+
* Added Hez Ronningen's patch for using the ISP lookup data file
|
12
|
+
|
13
|
+
== 0.5.0 2007-10-24
|
14
|
+
|
15
|
+
* 1 major enhancement:
|
16
|
+
* Initial release
|
data/README.rdoc
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
= geoip
|
2
|
+
|
3
|
+
http://github.com/cjheath/geoip
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
GeoIP searches a GeoIP database for a given host or IP address, and
|
8
|
+
returns information about the country where the IP address is allocated,
|
9
|
+
and the city, ISP and other information, if you have that database version.
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
Includes support for ASN data files, thanks to Roland Matiz.
|
14
|
+
This release adds support for timezone names, thanks to Tonni Aagesen.
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
require 'geoip'
|
19
|
+
|
20
|
+
# Use the country database:
|
21
|
+
c = GeoIP.new('GeoIP.dat').country('www.nokia.com')
|
22
|
+
=> ["www.nokia.com", "147.243.3.83", 69, "FI", "FIN", "Finland", "EU"]
|
23
|
+
c.country_code3
|
24
|
+
=> "FIN"
|
25
|
+
c.to_hash
|
26
|
+
=> {:country_code3=>"FIN", :country_name=>"Finland", :continent_code=>"EU", :request=>"www.nokia.com", :country_code=>69, :country_code2=>"FI", :ip=>"147.243.3.83"}
|
27
|
+
|
28
|
+
Returned values are the requested hostname, the IP address as a dotted quad,
|
29
|
+
Maxmind's country code, the ISO3166-1 alpha-2 country code, the ISO3166-2 alpha-3
|
30
|
+
country code, the ISO3166 country name, and the continent code.
|
31
|
+
|
32
|
+
# Use the city database:
|
33
|
+
c = GeoIP.new('GeoLiteCity.dat').city('github.com')
|
34
|
+
=> ["github.com", "207.97.227.239", "US", "USA", "United States", "NA", "CA", "San Francisco", "94110", 37.7484, -122.4156, 807, 415, "America/Los_Angeles"]
|
35
|
+
>> c.longitude
|
36
|
+
=> -122.4156
|
37
|
+
>> c.timezone
|
38
|
+
=> "America/Los_Angeles"
|
39
|
+
|
40
|
+
GeoIP.new('GeoCity.dat').city('github.com')
|
41
|
+
=> ["github.com", "207.97.227.239", "US", "USA", "United States", "NA", "CA", "San Francisco", "94110", 37.7484, -122.4156, 807, 415, "America/Los_Angeles"]
|
42
|
+
|
43
|
+
Returned values are the requested hostname, the IP address as a dotted quad,
|
44
|
+
the ISO3166-1 alpha-2 country code, the ISO3166-2 alpha-3 country code, the
|
45
|
+
ISO3166 country name, the continent code, the region (state or territory) name,
|
46
|
+
city name, postal_code/zipcode, latitude, longitude, USA DMA code, USA area code,
|
47
|
+
timezone name.
|
48
|
+
|
49
|
+
Result arrays from both city and country have mixed-in accessor methods as appropriate:
|
50
|
+
request, ip, country_code, country_code2, country_code3, country_name, continent_code,
|
51
|
+
region_name, city_name, postal_code, latitude, longitude, dma_code, area_code, timezone
|
52
|
+
|
53
|
+
GeoIP.new('GeoIPASNum.dat').asn("www.fsb.ru")
|
54
|
+
=> ["AS8342", "RTComm.RU Autonomous System"]
|
55
|
+
|
56
|
+
== REQUIREMENTS:
|
57
|
+
|
58
|
+
You need one of the free GeoLite country, city or ASN databases, or a subscription database version.
|
59
|
+
The last known download locations for the GeoLite database versions are
|
60
|
+
<http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz>,
|
61
|
+
<http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz>,
|
62
|
+
<http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz>.
|
63
|
+
|
64
|
+
This API requires the file to be decompressed for searching. Other versions
|
65
|
+
of this database are available for purchase which contain more detailed
|
66
|
+
information, but this information is not returned by this implementation.
|
67
|
+
See www.maxmind.com for more information.
|
68
|
+
|
69
|
+
== INSTALL:
|
70
|
+
|
71
|
+
sudo gem install geoip
|
72
|
+
|
73
|
+
== LICENSE:
|
74
|
+
|
75
|
+
This version Copyright (C) 2005 Clifford Heath
|
76
|
+
Derived from the C version, Copyright (C) 2003 MaxMind LLC
|
77
|
+
|
78
|
+
This library is free software; you can redistribute it and/or
|
79
|
+
modify it under the terms of the GNU General Public
|
80
|
+
License as published by the Free Software Foundation; either
|
81
|
+
version 2.1 of the License, or (at your option) any later version.
|
82
|
+
|
83
|
+
This library is distributed in the hope that it will be useful,
|
84
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
85
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
86
|
+
General Public License for more details.
|
87
|
+
|
88
|
+
You should have received a copy of the GNU General Public
|
89
|
+
License along with this library; if not, write to the Free Software
|
90
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'psych'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
require 'jeweler'
|
6
|
+
require './lib/geoip'
|
7
|
+
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
10
|
+
gem.name = "adept_geoip"
|
11
|
+
gem.version = GeoIP::VERSION
|
12
|
+
gem.homepage = "https://github.com/AdeptMobile/geoip"
|
13
|
+
gem.license = "MIT"
|
14
|
+
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.Forked by Adept Mobile to modify/extend.}
|
15
|
+
gem.description = %Q{GeoIP searches a GeoIP database for a given host or IP address, and
|
16
|
+
returns information about the country where the IP address is allocated,
|
17
|
+
and the city, ISP and other information, if you have that database version. Forked by Adept Mobile to modify/extend.}
|
18
|
+
gem.email = %w[craig.heneveld@adeptmobi.com]
|
19
|
+
gem.authors = ["Craig Heneveld"]
|
20
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
21
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
22
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
23
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
task :default => :test
|
34
|
+
|
35
|
+
require 'rake/rdoctask'
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
rdoc.rdoc_dir = 'rdoc'
|
38
|
+
rdoc.title = "adept_geoip #{GeoIP::VERSION}"
|
39
|
+
rdoc.rdoc_files.include('README.rdoc')
|
40
|
+
rdoc.rdoc_files.include('History.rdoc')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Generate website files'
|
45
|
+
task :website_generate do
|
46
|
+
sh %q{ruby script/txt2html website/index.txt > website/index.html}
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'Upload website files via rsync'
|
50
|
+
task :website_upload do
|
51
|
+
local_dir = 'website'
|
52
|
+
website_config = YAML.load(File.read("config/website.yml"))
|
53
|
+
host = website_config["host"]
|
54
|
+
host = host ? "#{host}:" : ""
|
55
|
+
remote_dir = website_config["remote_dir"]
|
56
|
+
sh %{rsync -aCv #{local_dir}/ #{host}#{remote_dir}}
|
57
|
+
end
|
58
|
+
|
data/adept_geoip.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{adept_geoip}
|
8
|
+
s.version = "1.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Craig Heneveld}]
|
12
|
+
s.date = %q{2012-02-21}
|
13
|
+
s.description = %q{GeoIP searches a GeoIP database for a given host or IP address, and
|
14
|
+
returns information about the country where the IP address is allocated,
|
15
|
+
and the city, ISP and other information, if you have that database version. Forked by Adept Mobile to modify/extend.}
|
16
|
+
s.email = [%q{craig.heneveld@adeptmobi.com}]
|
17
|
+
s.executables = [%q{geoip}]
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
"History.rdoc",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"adept_geoip.gemspec",
|
26
|
+
"bin/geoip",
|
27
|
+
"config/website.yml",
|
28
|
+
"data/geoip/country_code.yml",
|
29
|
+
"data/geoip/country_code3.yml",
|
30
|
+
"data/geoip/country_continent.yml",
|
31
|
+
"data/geoip/country_name.yml",
|
32
|
+
"data/geoip/time_zone.yml",
|
33
|
+
"geoip.gemspec",
|
34
|
+
"lib/geoip.rb",
|
35
|
+
"script/destroy",
|
36
|
+
"script/generate",
|
37
|
+
"script/txt2html",
|
38
|
+
"test/test_geoip.rb",
|
39
|
+
"test/test_helper.rb",
|
40
|
+
"website/index.txt",
|
41
|
+
"website/javascripts/rounded_corners_lite.inc.js",
|
42
|
+
"website/stylesheets/screen.css",
|
43
|
+
"website/template.rhtml"
|
44
|
+
]
|
45
|
+
s.homepage = %q{https://github.com/AdeptMobile/geoip}
|
46
|
+
s.licenses = [%q{MIT}]
|
47
|
+
s.require_paths = [%q{lib}]
|
48
|
+
s.rubygems_version = %q{1.8.8}
|
49
|
+
s.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.Forked by Adept Mobile to modify/extend.}
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
else
|
56
|
+
end
|
57
|
+
else
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/bin/geoip
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
|
4
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
5
|
+
|
6
|
+
require 'geoip'
|
7
|
+
|
8
|
+
data = '/usr/share/GeoIP/GeoIP.dat'
|
9
|
+
data = ARGV.shift if ARGV[0] =~ /\.dat\Z/
|
10
|
+
|
11
|
+
geoip = GeoIP.new data
|
12
|
+
req = ([GeoIP::GEOIP_CITY_EDITION_REV1, GeoIP::GEOIP_CITY_EDITION_REV0].include?(geoip.databaseType)) ? :city : :country
|
13
|
+
|
14
|
+
if ARGV.size > 0
|
15
|
+
ARGV.each { |a| p geoip.send(req, a) }
|
16
|
+
else
|
17
|
+
while (STDIN.isatty && print('geoip> '); ip = gets)
|
18
|
+
ip.chomp!
|
19
|
+
result = geoip.send(req, ip)
|
20
|
+
p result
|
21
|
+
end
|
22
|
+
STDIN.isatty && puts
|
23
|
+
end
|
data/config/website.yml
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
# Ordered list of the ISO3166 2-character country codes, ordered by GeoIP ID
|
2
|
+
---
|
3
|
+
- --
|
4
|
+
- AP
|
5
|
+
- EU
|
6
|
+
- AD
|
7
|
+
- AE
|
8
|
+
- AF
|
9
|
+
- AG
|
10
|
+
- AI
|
11
|
+
- AL
|
12
|
+
- AM
|
13
|
+
- AN
|
14
|
+
- AO
|
15
|
+
- AQ
|
16
|
+
- AR
|
17
|
+
- AS
|
18
|
+
- AT
|
19
|
+
- AU
|
20
|
+
- AW
|
21
|
+
- AZ
|
22
|
+
- BA
|
23
|
+
- BB
|
24
|
+
- BD
|
25
|
+
- BE
|
26
|
+
- BF
|
27
|
+
- BG
|
28
|
+
- BH
|
29
|
+
- BI
|
30
|
+
- BJ
|
31
|
+
- BM
|
32
|
+
- BN
|
33
|
+
- BO
|
34
|
+
- BR
|
35
|
+
- BS
|
36
|
+
- BT
|
37
|
+
- BV
|
38
|
+
- BW
|
39
|
+
- BY
|
40
|
+
- BZ
|
41
|
+
- CA
|
42
|
+
- CC
|
43
|
+
- CD
|
44
|
+
- CF
|
45
|
+
- CG
|
46
|
+
- CH
|
47
|
+
- CI
|
48
|
+
- CK
|
49
|
+
- CL
|
50
|
+
- CM
|
51
|
+
- CN
|
52
|
+
- CO
|
53
|
+
- CR
|
54
|
+
- CU
|
55
|
+
- CV
|
56
|
+
- CX
|
57
|
+
- CY
|
58
|
+
- CZ
|
59
|
+
- DE
|
60
|
+
- DJ
|
61
|
+
- DK
|
62
|
+
- DM
|
63
|
+
- DO
|
64
|
+
- DZ
|
65
|
+
- EC
|
66
|
+
- EE
|
67
|
+
- EG
|
68
|
+
- EH
|
69
|
+
- ER
|
70
|
+
- ES
|
71
|
+
- ET
|
72
|
+
- FI
|
73
|
+
- FJ
|
74
|
+
- FK
|
75
|
+
- FM
|
76
|
+
- FO
|
77
|
+
- FR
|
78
|
+
- FX
|
79
|
+
- GA
|
80
|
+
- GB
|
81
|
+
- GD
|
82
|
+
- GE
|
83
|
+
- GF
|
84
|
+
- GH
|
85
|
+
- GI
|
86
|
+
- GL
|
87
|
+
- GM
|
88
|
+
- GN
|
89
|
+
- GP
|
90
|
+
- GQ
|
91
|
+
- GR
|
92
|
+
- GS
|
93
|
+
- GT
|
94
|
+
- GU
|
95
|
+
- GW
|
96
|
+
- GY
|
97
|
+
- HK
|
98
|
+
- HM
|
99
|
+
- HN
|
100
|
+
- HR
|
101
|
+
- HT
|
102
|
+
- HU
|
103
|
+
- ID
|
104
|
+
- IE
|
105
|
+
- IL
|
106
|
+
- IN
|
107
|
+
- IO
|
108
|
+
- IQ
|
109
|
+
- IR
|
110
|
+
- IS
|
111
|
+
- IT
|
112
|
+
- JM
|
113
|
+
- JO
|
114
|
+
- JP
|
115
|
+
- KE
|
116
|
+
- KG
|
117
|
+
- KH
|
118
|
+
- KI
|
119
|
+
- KM
|
120
|
+
- KN
|
121
|
+
- KP
|
122
|
+
- KR
|
123
|
+
- KW
|
124
|
+
- KY
|
125
|
+
- KZ
|
126
|
+
- LA
|
127
|
+
- LB
|
128
|
+
- LC
|
129
|
+
- LI
|
130
|
+
- LK
|
131
|
+
- LR
|
132
|
+
- LS
|
133
|
+
- LT
|
134
|
+
- LU
|
135
|
+
- LV
|
136
|
+
- LY
|
137
|
+
- MA
|
138
|
+
- MC
|
139
|
+
- MD
|
140
|
+
- MG
|
141
|
+
- MH
|
142
|
+
- MK
|
143
|
+
- ML
|
144
|
+
- MM
|
145
|
+
- MN
|
146
|
+
- MO
|
147
|
+
- MP
|
148
|
+
- MQ
|
149
|
+
- MR
|
150
|
+
- MS
|
151
|
+
- MT
|
152
|
+
- MU
|
153
|
+
- MV
|
154
|
+
- MW
|
155
|
+
- MX
|
156
|
+
- MY
|
157
|
+
- MZ
|
158
|
+
- NA
|
159
|
+
- NC
|
160
|
+
- NE
|
161
|
+
- NF
|
162
|
+
- NG
|
163
|
+
- NI
|
164
|
+
- NL
|
165
|
+
- "NO"
|
166
|
+
- NP
|
167
|
+
- NR
|
168
|
+
- NU
|
169
|
+
- NZ
|
170
|
+
- OM
|
171
|
+
- PA
|
172
|
+
- PE
|
173
|
+
- PF
|
174
|
+
- PG
|
175
|
+
- PH
|
176
|
+
- PK
|
177
|
+
- PL
|
178
|
+
- PM
|
179
|
+
- PN
|
180
|
+
- PR
|
181
|
+
- PS
|
182
|
+
- PT
|
183
|
+
- PW
|
184
|
+
- PY
|
185
|
+
- QA
|
186
|
+
- RE
|
187
|
+
- RO
|
188
|
+
- RU
|
189
|
+
- RW
|
190
|
+
- SA
|
191
|
+
- SB
|
192
|
+
- SC
|
193
|
+
- SD
|
194
|
+
- SE
|
195
|
+
- SG
|
196
|
+
- SH
|
197
|
+
- SI
|
198
|
+
- SJ
|
199
|
+
- SK
|
200
|
+
- SL
|
201
|
+
- SM
|
202
|
+
- SN
|
203
|
+
- SO
|
204
|
+
- SR
|
205
|
+
- ST
|
206
|
+
- SV
|
207
|
+
- SY
|
208
|
+
- SZ
|
209
|
+
- TC
|
210
|
+
- TD
|
211
|
+
- TF
|
212
|
+
- TG
|
213
|
+
- TH
|
214
|
+
- TJ
|
215
|
+
- TK
|
216
|
+
- TM
|
217
|
+
- TN
|
218
|
+
- TO
|
219
|
+
- TL
|
220
|
+
- TR
|
221
|
+
- TT
|
222
|
+
- TV
|
223
|
+
- TW
|
224
|
+
- TZ
|
225
|
+
- UA
|
226
|
+
- UG
|
227
|
+
- UM
|
228
|
+
- US
|
229
|
+
- UY
|
230
|
+
- UZ
|
231
|
+
- VA
|
232
|
+
- VC
|
233
|
+
- VE
|
234
|
+
- VG
|
235
|
+
- VI
|
236
|
+
- VN
|
237
|
+
- VU
|
238
|
+
- WF
|
239
|
+
- WS
|
240
|
+
- YE
|
241
|
+
- YT
|
242
|
+
- RS
|
243
|
+
- ZA
|
244
|
+
- ZM
|
245
|
+
- ME
|
246
|
+
- ZW
|
247
|
+
- A1
|
248
|
+
- A2
|
249
|
+
- O1
|
250
|
+
- AX
|
251
|
+
- GG
|
252
|
+
- IM
|
253
|
+
- JE
|
254
|
+
- BL
|
255
|
+
- MF
|