Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 314 lines (218 sloc) 7.777 kb
1d333e1 edited new README.md
kuno authored
1 __GeoIP binding for nodejs__
93e31c3 changed travis img position
kuno authored
2 [![build status](https://secure.travis-ci.org/kuno/GeoIP.png)](http://travis-ci.org/kuno/GeoIP)
7d5ec3c no php files
kuno authored
3
a860235 fixed miss-spelling in README
kuno authored
4 Get geolocation information based on domain or IP address.
d65607f add changelog
kuno authored
5
4a64141 nts
kuno authored
6 ##Important Notification
de18819 added early warning for v0.4.0
kuno authored
7
f210c12 emphasized version
kuno authored
8 From __v0.4.0__, geoip will be bind to libgeoip >= __1.4.7__, which is a C library, __the api also has been changed__.
de18819 added early warning for v0.4.0
kuno authored
9
716895c rename architecture diagram
kuno authored
10 ###Technical Architecture
c7e591b added guidance for installation of geoip c library
kuno authored
11
08cbda9 @rockdog Fixed typo
rockdog authored
12 ![new_architecture](https://github.com/kuno/GeoIP/raw/master/misc/new_architecture.png)
de18819 added early warning for v0.4.0
kuno authored
13
c5614fe v0.2.1 devel finished
kuno authored
14
611ac2e added new libiconv dependency explanination
kuno authored
15 ###Dependency
16
17 ####libgeoip C library
c7e591b added guidance for installation of geoip c library
kuno authored
18
19 If your os has a system package manager (e.g, on linux, apt of ubuntu, yum of fedora, pacman of arch. MacPorts and homebrew on OSX),
20
21 then, there is a very high possibility that there is alreay a geoip c library package inside the repository.
22
23 If not, you can build for yourself:
24
25 wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.7.tar.gz
05a71c9 nts
kuno authored
26 tar -xvzf GeoIP-1.4.7.tar.gz
c7e591b added guidance for installation of geoip c library
kuno authored
27 cd GeoIP-1.4.7
08cbda9 @rockdog Fixed typo
rockdog authored
28 ./configure --prefix=/usr
29 make
c7e591b added guidance for installation of geoip c library
kuno authored
30 sudo make install
31
8cbe21f added dependency policy
kuno authored
32 #####Dependency Policy
33
34 GeoIP takes the so call 'two steps' dependency policy, which means the minimal version of libgeoip is always the previous release of the latest one.
35
60cf111 typo
kuno authored
36 For example, currently(April 2012) latest release of libgeoip is 1.4.8, so the minimal dependency will be the previous release, which is 1.4.7, and so on.
c7e591b added guidance for installation of geoip c library
kuno authored
37
dcb766b clean README.md
kuno authored
38 ##Data
7d5ec3c no php files
kuno authored
39
5879871 added comments to sample.js
kuno authored
40 Befor you can use this package, you need to download or buy some data from [www.maxmind.com](http://www.maxmind.com/app/ip-location).
773b7fa try 4
kuno authored
41
135460a fixed README.md typos
kuno authored
42 There are some free databases among some commercial versions, the free databases can be found [here](http://geolite.maxmind.com/download/geoip/database/).
a860235 fixed miss-spelling in README
kuno authored
43
999b653 added data format warning
kuno authored
44
fbc3fd2 update README
kuno authored
45 ##Installation
a860235 fixed miss-spelling in README
kuno authored
46
c2eaec2 v0.4.6
kuno authored
47 ### for nodejs 0.8.x
48
49 [sudo] npm install geoip [-g]
50
fbc3fd2 update README
kuno authored
51 ### for nodejs 0.6.x
0605938 added 0.4.5 readme content
kuno authored
52
fbc3fd2 update README
kuno authored
53 [sudo] npm install geoip@0.4.5 [-g]
773b7fa try 4
kuno authored
54
c6704ee nts
kuno authored
55 ### for nodejs 0.4.x
0605938 added 0.4.5 readme content
kuno authored
56
57 [sudo] npm install geoip@0.4.4 [-g]
c5614fe v0.2.1 devel finished
kuno authored
58
20f7fa0 nts
kuno authored
59 ### for nodejs older than 0.4.0
c5614fe v0.2.1 devel finished
kuno authored
60
1d333e1 edited new README.md
kuno authored
61 From v0.4.0, geoip need nodejs >= 0.4.0, if you want to use it on old nodejs, you can:
7d5ec3c no php files
kuno authored
62
1d333e1 edited new README.md
kuno authored
63 npm install geoip@0.3.4-1
7d5ec3c no php files
kuno authored
64
65
dcb766b clean README.md
kuno authored
66 ##Usage
67
1d333e1 edited new README.md
kuno authored
68 ###Check edition
891dd61 added check documents
kuno authored
69
1d333e1 edited new README.md
kuno authored
70 var edition = geoip.check('/path/to/file');
891dd61 added check documents
kuno authored
71
1d333e1 edited new README.md
kuno authored
72 console.log(edition); // output 'country', 'city', 'org'... so on
251db8f added temporary live demo
kuno authored
73
1d333e1 edited new README.md
kuno authored
74 ###Create a new instance of sub-module, for example:
891dd61 added check documents
kuno authored
75
1d333e1 edited new README.md
kuno authored
76 var city = new geoip.City('/path/to/GeoLiteCity.dat', false); // not to cache the database
891dd61 added check documents
kuno authored
77
1d333e1 edited new README.md
kuno authored
78 var city = new geoip.City('/path/to/GeoLiteCity.dat'); // the default option is cache
f508273 added async style open file
kuno authored
79
623e64a added v0.4.2 changelog
kuno authored
80 ###Update database on the fly:
81
82 city.update('/path/to/new/GeoLiteCity.dat');
83
0fc8477 edited README.md
kuno authored
84 ##Modules
891dd61 added check documents
kuno authored
85
0fc8477 edited README.md
kuno authored
86 ###Country
7d5ec3c no php files
kuno authored
87
4206dff v0.4.4 rolling out
kuno authored
88 ipv4 address lookup
38081d9 added new country ipv6 module introduction
kuno authored
89
42db086 nst
kuno authored
90 // Open the country data file
0fc8477 edited README.md
kuno authored
91 var Country = geoip.Country;
7d5ec3c no php files
kuno authored
92
9949c08 added ipv6 country doc
kuno authored
93 var country = new Country('/path/to/GeoIP.dat');
4c7ca09 re-add GeoIP.dat
kuno authored
94
f9b2f45 added country.lookup6 method doc
kuno authored
95 // Synchronous method(the recommended way):
c00593c fixed country.lookupSync typo
kuno authored
96 var country_obj = country.lookupSync('8.8.8.8');
f7dfb2e ready push to npm repositry
kuno authored
97
1d333e1 edited new README.md
kuno authored
98 console.log(country_obj);
99 /*
100 { country_code: 'US',
101 country_code3: 'USA',
102 country_name: 'United States',
08cbda9 @rockdog Fixed typo
rockdog authored
103 continent_code: 'NA'
f9b2f45 added country.lookup6 method doc
kuno authored
104 }
1d333e1 edited new README.md
kuno authored
105 */
7d5ec3c no php files
kuno authored
106
f9b2f45 added country.lookup6 method doc
kuno authored
107 // Asynchronous method:
00bbf08 added err check in async method
kuno authored
108 country.lookup('www.google.com', function(err, data) {
109 if (err) {throw err;}
110 if (data) { // if not found, just return null
1d333e1 edited new README.md
kuno authored
111 console.log(data); // same as lookup method
112 }
1318418 nts
kuno authored
113 });
4c7ca09 re-add GeoIP.dat
kuno authored
114
4206dff v0.4.4 rolling out
kuno authored
115 ipv6 address lookup (Currently only Country and City module supports ipv6)
9949c08 added ipv6 country doc
kuno authored
116
38081d9 added new country ipv6 module introduction
kuno authored
117 // Open the ipv6 edition of country module
118 var Country6 = geoip.Country6;
119
120 var country_v6 = new Country6('/path/to/GeoIPv6.dat');
9949c08 added ipv6 country doc
kuno authored
121
f9b2f45 added country.lookup6 method doc
kuno authored
122 // Synchronous method
38081d9 added new country ipv6 module introduction
kuno authored
123 var country_obj_v6 = country_v6.lookupSync('2607:f0d0:1002:0051:0000:0000:0000:0004');
9949c08 added ipv6 country doc
kuno authored
124
125 console.log(country_obj_v6); // Same as ipv4
126 /*
127 { country_code: 'US',
128 country_code3: 'USA',
129 country_name: 'United States',
08cbda9 @rockdog Fixed typo
rockdog authored
130 continent_code: 'NA'
9949c08 added ipv6 country doc
kuno authored
131 }
132 */
133
f9b2f45 added country.lookup6 method doc
kuno authored
134 // Asynchronous method
38081d9 added new country ipv6 module introduction
kuno authored
135 country_v6.lookup('2400:2352:b0f1:36c5:aa9d:694a:2f98:40bd', function(err, data_v6) {
f9b2f45 added country.lookup6 method doc
kuno authored
136 if (err) {throw err;}
137 if (data_v6) {
138 console.log(data_v6);
139 /*
08cbda9 @rockdog Fixed typo
rockdog authored
140 {
f9b2f45 added country.lookup6 method doc
kuno authored
141 country_code: 'JP',
142 country_code3: 'JPN',
143 country_name: 'Japan',
08cbda9 @rockdog Fixed typo
rockdog authored
144 continent_code: 'AS'
f9b2f45 added country.lookup6 method doc
kuno authored
145 }
146
147 */
148 }
149 });
150
dcb766b clean README.md
kuno authored
151
0fc8477 edited README.md
kuno authored
152 ###City
4c7ca09 re-add GeoIP.dat
kuno authored
153
4206dff v0.4.4 rolling out
kuno authored
154 ipv4 address lookup
155
8399722 nst
kuno authored
156 // Open the GeoLiteCity.dat file first.
0fc8477 edited README.md
kuno authored
157 var City = geoip.City;
1d333e1 edited new README.md
kuno authored
158 var city = new City('/path/to/GeoLiteCity.dat');
251db8f added temporary live demo
kuno authored
159
4206dff v0.4.4 rolling out
kuno authored
160 Synchronous method:
161
162 var city_obj = city.lookupSync('8.8.8.8');
163 console.log(city_obj);
164 /*
165 Return an object of city information
166 {
167 "country_code":"US",
168 "country_code3":"USA",
169 "country_name":"United States",
170 "continet_code":"NA",
171 "region":"CA",
172 "city":"Mountain View",
173 "postal_code":"94043",
174 "latitude":37.41919999999999,
175 "longitude":-122.0574,
176 "dma_code":807,
177 "metro_code":807,
178 "area_code":650
179 }
180 */
181
182 Asynchronous method:
183
184 city.lookup('www.google.com', function(err, data) {
185 if (err) {throw err;}
186 if (data) {
187 console.log(data);
188 }
189 });
190
191
192 ipv6 address lookup
193
194 // Open the GeoLiteCityv6.dat file first.
195 var City6 = geoip.City6;
196 var city6 = new City6('/path/to/GeoLiteCityv6.dat');
197
198 Synchronous method:
199
dbd5612 I want to be Chengdu
kuno authored
200 var city6_obj = city6.lookupSync('2002:7679:b9af:db9b:ab51:501a:db4e:2d');
4206dff v0.4.4 rolling out
kuno authored
201 console.log(city6_obj);
202 /*
dbd5612 I want to be Chengdu
kuno authored
203 {
204 country_code: 'CN',
205 country_code3: 'CHN',
206 country_name: 'China',
207 region: '32',
208 city: 'Chengdu',
209 latitude: 30.66670036315918,
210 longitude: 104.06670379638672,
211 continent_code: 'AS'
71d04fc prepare for v0.4.0 release
kuno authored
212 }
4206dff v0.4.4 rolling out
kuno authored
213 */
251db8f added temporary live demo
kuno authored
214
4206dff v0.4.4 rolling out
kuno authored
215 Asynchronous method:
251db8f added temporary live demo
kuno authored
216
4206dff v0.4.4 rolling out
kuno authored
217 city6.lookup('2002:c6aa:2dc8:b719:4314:2a7d:e31c:fe73', function(err, data) {
00bbf08 added err check in async method
kuno authored
218 if (err) {throw err;}
1d333e1 edited new README.md
kuno authored
219 if (data) {
220 console.log(data);
4206dff v0.4.4 rolling out
kuno authored
221 /* As expected ,return an object that contains city information
222 {
223 country_code: 'US',
224 country_code3: 'USA',
225 country_name: 'United States',
226 region: 'CO',
227 city: 'Englewood',
228 postal_code: '80112',
229 latitude: 39.569000244140625,
230 longitude: -104.85820007324219,
231 continent_code: 'NA'
232 }
233 */
234 }
235 });
7cc6a5c add new content in README
kuno authored
236
0fc8477 edited README.md
kuno authored
237 ###Organization
dcb766b clean README.md
kuno authored
238
0fc8477 edited README.md
kuno authored
239 var Org = geoip.Org;
1d333e1 edited new README.md
kuno authored
240 var org = new Org('/path/to/file') // Org module can open three edition database 'org', 'asnum', 'isp'
7cc6a5c add new content in README
kuno authored
241
c00593c fixed country.lookupSync typo
kuno authored
242 Synchronous method:
adb4ed1 v0.3.0 finished!
kuno authored
243
c00593c fixed country.lookupSync typo
kuno authored
244 var org_str = org.lookupSync('8.8.8.8');
251db8f added temporary live demo
kuno authored
245
1d333e1 edited new README.md
kuno authored
246 console.log(org_str);
247 /*
248 The type of returned data is string, for example:
c5614fe v0.2.1 devel finished
kuno authored
249
1d333e1 edited new README.md
kuno authored
250 'Genuity'
251 'AS15169 Google Inc.'
08cbda9 @rockdog Fixed typo
rockdog authored
252
1d333e1 edited new README.md
kuno authored
253 no longer an object
254 */
251db8f added temporary live demo
kuno authored
255
c00593c fixed country.lookupSync typo
kuno authored
256 Asynchronous method:
251db8f added temporary live demo
kuno authored
257
00bbf08 added err check in async method
kuno authored
258 org.lookup('www.google.com', function(err, data) {
259 if (err) {throw err;}
1d333e1 edited new README.md
kuno authored
260 if (data) {
261 console.log(data);
262 }
251db8f added temporary live demo
kuno authored
263 });
264
265
6f767ab change README.md layor
kuno authored
266 ###Region
7cc6a5c add new content in README
kuno authored
267
0fc8477 edited README.md
kuno authored
268 var Region = geoip.Region;
1d333e1 edited new README.md
kuno authored
269 var region = new Region('/path/to/GeoIPRegion.dat');
7cc6a5c add new content in README
kuno authored
270
c00593c fixed country.lookupSync typo
kuno authored
271 Synchronous method:
adb4ed1 v0.3.0 finished!
kuno authored
272
08cbda9 @rockdog Fixed typo
rockdog authored
273 var region_obj = region.lookupSync('8.8.8.8');
274
1d333e1 edited new README.md
kuno authored
275 console.log('region_obj);
276 /*
277 region object has two properties:
278 { country_code: 'US', region: 'CO' }
279
280 */
7cc6a5c add new content in README
kuno authored
281
c00593c fixed country.lookupSync typo
kuno authored
282 Asynchronous method:
adb4ed1 v0.3.0 finished!
kuno authored
283
00bbf08 added err check in async method
kuno authored
284 region.lookup('www.google.com', function(err, data) {
285 if (err) {throw err;}
1d333e1 edited new README.md
kuno authored
286 if (data) {
287 console.log(data);
288 }
251db8f added temporary live demo
kuno authored
289 });
adb4ed1 v0.3.0 finished!
kuno authored
290
7cc6a5c add new content in README
kuno authored
291
6f767ab change README.md layor
kuno authored
292 ###NetSpeed
7cc6a5c add new content in README
kuno authored
293
0fc8477 edited README.md
kuno authored
294 var NetSpeed = geoip.NetSpeed;
1d333e1 edited new README.md
kuno authored
295 var netspeed = new NetSpeed('/path/to/GeoIPNetSpeed.dat');
251db8f added temporary live demo
kuno authored
296
c00593c fixed country.lookupSync typo
kuno authored
297 Synchronous method:
7cc6a5c add new content in README
kuno authored
298
1d333e1 edited new README.md
kuno authored
299 var netspeed_str = netspeed.lookupSync('8.8.8.8');
08cbda9 @rockdog Fixed typo
rockdog authored
300
1d333e1 edited new README.md
kuno authored
301 console.log(netspeed_str);
302 /*
303 netspeed_str just a simple string, 'Dialup', 'Corprate'... so on
304 */
adb4ed1 v0.3.0 finished!
kuno authored
305
c00593c fixed country.lookupSync typo
kuno authored
306 Asynchronous method:
7cc6a5c add new content in README
kuno authored
307
00bbf08 added err check in async method
kuno authored
308 netspeed.lookup('www.google.com', function(err, data) {
309 if (err) {throw err;}
1d333e1 edited new README.md
kuno authored
310 if (data) {
311 console.log(data); // Maybe return 'unknow' or different from lookup method
312 }
251db8f added temporary live demo
kuno authored
313 });
Something went wrong with that request. Please try again.