geoip-lite2 2.1.6 β 2.1.8
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.
- package/.gitignore +2 -1
- package/AUTHORS +1 -0
- package/LICENSE +1 -0
- package/README.md +14 -13
- package/data/city.checksum +1 -1
- package/data/country.checksum +1 -1
- package/data/geoip-city-names.dat +0 -0
- package/data/geoip-city.dat +0 -0
- package/data/geoip-city6.dat +0 -0
- package/data/geoip-country.dat +0 -0
- package/data/geoip-country6.dat +0 -0
- package/lib/geoip.js +1 -1
- package/lib/utils.js +1 -1
- package/package.json +77 -77
- package/utils/updatedb.js +1 -1
package/.gitignore
CHANGED
package/AUTHORS
CHANGED
package/LICENSE
CHANGED
|
@@ -20,6 +20,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
20
20
|
See the License for the specific language governing permissions and
|
|
21
21
|
limitations under the License.
|
|
22
22
|
|
|
23
|
+
|
|
23
24
|
DATABASES LICENSE (GeoLite2 databases)
|
|
24
25
|
|
|
25
26
|
Copyright (c) 2012-2018 MaxMind, Inc. All Rights Reserved.
|
package/README.md
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
A native Node.js API for the GeoLite data from MaxMind
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
</
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>πΊοΈ GeoIP-Lite2 v2.1 - Now even faster!</h1>
|
|
3
|
+
A native Node.js API for the GeoLite data from MaxMind.<br>
|
|
4
|
+
This product includes GeoLite data created by MaxMind, available from: https://www.maxmind.com
|
|
5
|
+
<br><br>
|
|
6
|
+
<a href="https://www.npmjs.com/package/geoip-lite2" target="_blank" title="geoip-lite2 - npm" style="text-decoration:none">
|
|
7
|
+
<img src="https://img.shields.io/npm/dt/geoip-lite2?maxAge=3600" alt="The number of downloads">
|
|
8
|
+
<img src="https://img.shields.io/github/last-commit/sefinek24/geoip-lite2" alt="Last commit">
|
|
9
|
+
<img src="https://img.shields.io/github/issues/sefinek24/geoip-lite2" alt="Issues">
|
|
10
|
+
<img src="https://img.shields.io/github/commit-activity/w/sefinek24/geoip-lite2" alt="Commit activity">
|
|
11
|
+
<img src="https://img.shields.io/github/languages/code-size/sefinek24/geoip-lite2" alt="Code size">
|
|
12
|
+
</a>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
14
15
|
|
|
15
16
|
π Improved GeoIP Module by [Sefinek](https://sefinek.net)
|
|
16
17
|
------------
|
package/data/city.checksum
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
ef6b46b8a2d067b8d453f763f63c14180f086a095a0cdf82bb7378b79cc20479 GeoLite2-City-CSV_20230922.zip
|
package/data/country.checksum
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
e5e56baea61630fa8d22f76ca804fd353024ac38364abd2a65c126be7e7fab8c GeoLite2-Country-CSV_20230922.zip
|
|
Binary file
|
package/data/geoip-city.dat
CHANGED
|
Binary file
|
package/data/geoip-city6.dat
CHANGED
|
Binary file
|
package/data/geoip-country.dat
CHANGED
|
Binary file
|
package/data/geoip-country6.dat
CHANGED
|
Binary file
|
package/lib/geoip.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require('node:fs'),t=require('node:net'),r=require('node:path'),n=require('async'),i=require('./utils.js'),o=require('./fsWatcher.js'),{version:a}=require('../package.json');e.existsSync=e.existsSync||r.existsSync;const c='dataWatcher',f=r.resolve(__dirname,global.geoDataDir||process.env.geoDataDIR||'../data/'),s={city:r.join(f,'geoip-city.dat'),city6:r.join(f,'geoip-city6.dat'),cityNames:r.join(f,'geoip-city-names.dat'),country:r.join(f,'geoip-country.dat'),country6:r.join(f,'geoip-country6.dat')},l=[[i.aton4('10.0.0.0'),i.aton4('10.255.255.255')],[i.aton4('172.16.0.0'),i.aton4('172.31.255.255')],[i.aton4('192.168.0.0'),i.aton4('192.168.255.255')]],u={firstIP:null,lastIP:null,lastLine:0,locationBuffer:null,locationRecordSize:88,mainBuffer:null,recordSize:24},d={firstIP:null,lastIP:null,lastLine:0,mainBuffer:null,recordSize:48};let y=JSON.parse(JSON.stringify(u)),S=JSON.parse(JSON.stringify(d));const p=e=>{let t,r,n=0,i=y.lastIP,o=y.lastLine,a=y.firstIP;const c=y.mainBuffer,f=y.locationBuffer,s=l,u=y.recordSize,d=y.locationRecordSize;let S;const p={range:'',country:'',region:'',eu:'',timezone:'',city:'',ll:[0,0]};if(e>y.lastIP||e<y.firstIP)return null;for(S=0;S<s.length;S++)if(e>=s[S][0]&&e<=s[S][1])return null;for(;;){if(t=Math.round((o-n)/2)+n,i=c.readUInt32BE(t*u),a=c.readUInt32BE(t*u+4),i<=e&&a>=e)return p.range=[i,a],10===u?p.country=c.toString('utf8',t*u+8,t*u+10):(r=c.readUInt32BE(t*u+8),p.country=f.toString('utf8',r*d,r*d+2).replace(/\u0000.*/,''),p.region=f.toString('utf8',r*d+2,r*d+5).replace(/\u0000.*/,''),p.metro=f.readInt32BE(r*d+5),p.ll[0]=c.readInt32BE(t*u+12)/1e4,p.ll[1]=c.readInt32BE(t*u+16)/1e4,p.area=c.readUInt32BE(t*u+20),p.eu=f.toString('utf8',r*d+9,r*d+10).replace(/\u0000.*/,''),p.timezone=f.toString('utf8',r*d+10,r*d+42).replace(/\u0000.*/,''),p.city=f.toString('utf8',r*d+42,r*d+d).replace(/\u0000.*/,'')),p;if(n===o)return null;n===o-1?t===n?n=o:o=n:i>e?o=t:a<e&&(n=t)}};function B(t){let r,i;const o=JSON.parse(JSON.stringify(u));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(s.cityNames,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,o.locationBuffer=Buffer.alloc(i),t(e)}))},t=>{e.read(r,o.locationBuffer,0,i,0,t)},t=>{e.close(r,t)},t=>{e.open(s.city,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(s.country,'r',((n,a)=>{n?t(n):(r=a,e.fstat(r,((e,r)=>{i=r.size,o.recordSize=10,t()})))}))}else t()}))},()=>{o.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,o.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(o.lastLine=i/o.recordSize-1,o.lastIP=o.mainBuffer.readUInt32BE(o.lastLine*o.recordSize+4),o.firstIP=o.mainBuffer.readUInt32BE(0),y=o),t(e)}))}]);else{try{if(r=e.openSync(s.cityNames,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'};y.locationBuffer=Buffer.alloc(i),e.readSync(r,y.locationBuffer,0,i,0),e.closeSync(r),r=e.openSync(s.city,'r'),i=e.fstatSync(r).size}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(s.country,'r'),i=e.fstatSync(r).size,y.recordSize=10}y.mainBuffer=Buffer.alloc(i),e.readSync(r,y.mainBuffer,0,i,0),e.closeSync(r),y.lastLine=i/y.recordSize-1,y.lastIP=y.mainBuffer.readUInt32BE(y.lastLine*y.recordSize+4),y.firstIP=y.mainBuffer.readUInt32BE(0)}}function g(t){let r,i;const o=JSON.parse(JSON.stringify(d));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(s.city6,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(s.country6,'r',((n,a)=>{n?t(n):(r=a,e.fstat(r,((e,r)=>{i=r.size,o.recordSize=34,t()})))}))}else t()}))},()=>{o.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,o.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(o.lastLine=i/o.recordSize-1,S=o),t(e)}))}]);else{try{if(r=e.openSync(s.city6,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'}}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(s.country6,'r'),i=e.fstatSync(r).size,S.recordSize=34}S.mainBuffer=Buffer.alloc(i),e.readSync(r,S.mainBuffer,0,i,0),e.closeSync(r),S.lastLine=i/S.recordSize-1}}module.exports={cmp:i.cmp,lookup:e=>{if(!e)return null;if('number'==typeof e)return p(e);if(4===t.isIP(e))return p(i.aton4(e));if(6===t.isIP(e)){const t=(e=>{const t=e.toUpperCase(),r=['0:0:0:0:0:FFFF:','::FFFF:'];for(let e=0;e<r.length;e++){const n=r[e];if(0===t.indexOf(n))return t.substring(n.length)}return null})(e);return t?p(i.aton4(t)):(e=>{const t=S.mainBuffer,r=S.recordSize,n=y.locationBuffer,o=y.locationRecordSize,a={range:'',country:'',region:'',city:'',ll:[0,0]},c=(e,n)=>{let i
|
|
1
|
+
const e=require('node:fs'),t=require('node:net'),r=require('node:path'),n=require('async'),i=require('./utils.js'),o=require('./fsWatcher.js'),{version:a}=require('../package.json');e.existsSync=e.existsSync||r.existsSync;const c='dataWatcher',f=r.resolve(__dirname,global.geoDataDir||process.env.geoDataDIR||'../data/'),s={city:r.join(f,'geoip-city.dat'),city6:r.join(f,'geoip-city6.dat'),cityNames:r.join(f,'geoip-city-names.dat'),country:r.join(f,'geoip-country.dat'),country6:r.join(f,'geoip-country6.dat')},l=[[i.aton4('10.0.0.0'),i.aton4('10.255.255.255')],[i.aton4('172.16.0.0'),i.aton4('172.31.255.255')],[i.aton4('192.168.0.0'),i.aton4('192.168.255.255')]],u={firstIP:null,lastIP:null,lastLine:0,locationBuffer:null,locationRecordSize:88,mainBuffer:null,recordSize:24},d={firstIP:null,lastIP:null,lastLine:0,mainBuffer:null,recordSize:48};let y=JSON.parse(JSON.stringify(u)),S=JSON.parse(JSON.stringify(d));const p=e=>{let t,r,n=0,i=y.lastIP,o=y.lastLine,a=y.firstIP;const c=y.mainBuffer,f=y.locationBuffer,s=l,u=y.recordSize,d=y.locationRecordSize;let S;const p={range:'',country:'',region:'',eu:'',timezone:'',city:'',ll:[0,0]};if(e>y.lastIP||e<y.firstIP)return null;for(S=0;S<s.length;S++)if(e>=s[S][0]&&e<=s[S][1])return null;for(;;){if(t=Math.round((o-n)/2)+n,i=c.readUInt32BE(t*u),a=c.readUInt32BE(t*u+4),i<=e&&a>=e)return p.range=[i,a],10===u?p.country=c.toString('utf8',t*u+8,t*u+10):(r=c.readUInt32BE(t*u+8),p.country=f.toString('utf8',r*d,r*d+2).replace(/\u0000.*/,''),p.region=f.toString('utf8',r*d+2,r*d+5).replace(/\u0000.*/,''),p.metro=f.readInt32BE(r*d+5),p.ll[0]=c.readInt32BE(t*u+12)/1e4,p.ll[1]=c.readInt32BE(t*u+16)/1e4,p.area=c.readUInt32BE(t*u+20),p.eu=f.toString('utf8',r*d+9,r*d+10).replace(/\u0000.*/,''),p.timezone=f.toString('utf8',r*d+10,r*d+42).replace(/\u0000.*/,''),p.city=f.toString('utf8',r*d+42,r*d+d).replace(/\u0000.*/,'')),p;if(n===o)return null;n===o-1?t===n?n=o:o=n:i>e?o=t:a<e&&(n=t)}};function B(t){let r,i;const o=JSON.parse(JSON.stringify(u));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(s.cityNames,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,o.locationBuffer=Buffer.alloc(i),t(e)}))},t=>{e.read(r,o.locationBuffer,0,i,0,t)},t=>{e.close(r,t)},t=>{e.open(s.city,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(s.country,'r',((n,a)=>{n?t(n):(r=a,e.fstat(r,((e,r)=>{i=r.size,o.recordSize=10,t()})))}))}else t()}))},()=>{o.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,o.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(o.lastLine=i/o.recordSize-1,o.lastIP=o.mainBuffer.readUInt32BE(o.lastLine*o.recordSize+4),o.firstIP=o.mainBuffer.readUInt32BE(0),y=o),t(e)}))}]);else{try{if(r=e.openSync(s.cityNames,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'};y.locationBuffer=Buffer.alloc(i),e.readSync(r,y.locationBuffer,0,i,0),e.closeSync(r),r=e.openSync(s.city,'r'),i=e.fstatSync(r).size}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(s.country,'r'),i=e.fstatSync(r).size,y.recordSize=10}y.mainBuffer=Buffer.alloc(i),e.readSync(r,y.mainBuffer,0,i,0),e.closeSync(r),y.lastLine=i/y.recordSize-1,y.lastIP=y.mainBuffer.readUInt32BE(y.lastLine*y.recordSize+4),y.firstIP=y.mainBuffer.readUInt32BE(0)}}function g(t){let r,i;const o=JSON.parse(JSON.stringify(d));if('function'==typeof arguments[0])n.series([t=>{n.series([t=>{e.open(s.city6,'r',((e,n)=>{r=n,t(e)}))},t=>{e.fstat(r,((e,r)=>{i=r.size,t(e)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e.open(s.country6,'r',((n,a)=>{n?t(n):(r=a,e.fstat(r,((e,r)=>{i=r.size,o.recordSize=34,t()})))}))}else t()}))},()=>{o.mainBuffer=Buffer.alloc(i),n.series([t=>{e.read(r,o.mainBuffer,0,i,0,t)},t=>{e.close(r,t)}],(e=>{e||(o.lastLine=i/o.recordSize-1,S=o),t(e)}))}]);else{try{if(r=e.openSync(s.city6,'r'),i=e.fstatSync(r).size,0===i)throw{code:'EMPTY_FILE'}}catch(t){if('ENOENT'!==t.code&&'EBADF'!==t.code&&'EMPTY_FILE'!==t.code)throw t;r=e.openSync(s.country6,'r'),i=e.fstatSync(r).size,S.recordSize=34}S.mainBuffer=Buffer.alloc(i),e.readSync(r,S.mainBuffer,0,i,0),e.closeSync(r),S.lastLine=i/S.recordSize-1}}module.exports={cmp:i.cmp,lookup:e=>{if(!e)return null;if('number'==typeof e)return p(e);if(4===t.isIP(e))return p(i.aton4(e));if(6===t.isIP(e)){const t=(e=>{const t=e.toUpperCase(),r=['0:0:0:0:0:FFFF:','::FFFF:'];for(let e=0;e<r.length;e++){const n=r[e];if(0===t.indexOf(n))return t.substring(n.length)}return null})(e);return t?p(i.aton4(t)):(e=>{const t=S.mainBuffer,r=S.recordSize,n=y.locationBuffer,o=y.locationRecordSize,a={range:'',country:'',region:'',city:'',ll:[0,0]},c=(e,n)=>{let i;const o=[];for(i=0;i<2;i++)o.push(t.readUInt32BE(e*r+16*n+4*i));return o};S.lastIP=c(S.lastLine,1),S.firstIP=c(0,0);let f,s,l=0,u=S.lastIP,d=S.lastLine,p=S.firstIP;if(i.cmp6(e,S.lastIP)>0||i.cmp6(e,S.firstIP)<0)return null;for(;;){if(f=Math.round((d-l)/2)+l,u=c(f,0),p=c(f,1),i.cmp6(u,e)<=0&&i.cmp6(p,e)>=0)return 34===r?a.country=t.toString('utf8',f*r+32,f*r+34).replace(/\u0000.*/,''):(s=t.readUInt32BE(f*r+32),a.country=n.toString('utf8',s*o,s*o+2).replace(/\u0000.*/,''),a.region=n.toString('utf8',s*o+2,s*o+5).replace(/\u0000.*/,''),a.metro=n.readInt32BE(s*o+5),a.ll[0]=t.readInt32BE(f*r+36)/1e4,a.ll[1]=t.readInt32BE(f*r+40)/1e4,a.area=t.readUInt32BE(f*r+44),a.eu=n.toString('utf8',s*o+9,s*o+10).replace(/\u0000.*/,''),a.timezone=n.toString('utf8',s*o+10,s*o+42).replace(/\u0000.*/,''),a.city=n.toString('utf8',s*o+42,s*o+o).replace(/\u0000.*/,'')),a;if(l===d)return null;l===d-1?f===l?l=d:d=l:i.cmp6(u,e)>0?d=f:i.cmp6(p,e)<0&&(l=f)}})(i.aton6(e))}return null},pretty:e=>'string'==typeof e?e:'number'==typeof e?i.ntoa4(e):Array.isArray(e)?i.ntoa6(e):e,startWatchingDataUpdate:e=>{o.makeFsWatchFilter(c,f,6e4,(()=>{n.series([e=>{B(e)},e=>{g(e)}],e)}))},stopWatchingDataUpdate:()=>{o.stopWatching(c)},clear:()=>{y=JSON.parse(JSON.stringify(u)),S=JSON.parse(JSON.stringify(d))},reloadDataSync:()=>{B(),g()},reloadData:e=>{n.series([e=>{B(e)},e=>{g(e)}],e)},version:a},B(),g();
|
package/lib/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=module.exports={};t.aton4=
|
|
1
|
+
const t=module.exports={};t.aton4=t=>(t=t.split(/\./),(parseInt(t[0],10)<<24>>>0)+(parseInt(t[1],10)<<16>>>0)+(parseInt(t[2],10)<<8>>>0)+(parseInt(t[3],10)>>>0)),t.aton6=t=>{const n=(t=t.replace(/"/g,'').split(/:/)).length-1;let r;if(''===t[n]&&(t[n]=0),n<7)for(t.length=8,r=n;r>=0&&''!==t[r];r--)t[7-n+r]=t[r];for(r=0;r<8;r++)t[r]?t[r]=parseInt(t[r],16):t[r]=0;const e=[];for(r=0;r<4;r++)e.push((t[2*r]<<16)+t[2*r+1]>>>0);return e},t.cmp=(t,n)=>'number'==typeof t&&'number'==typeof n?t<n?-1:t>n?1:0:t instanceof Array&&n instanceof Array?this.cmp6(t,n):null,t.cmp6=(t,n)=>{for(let r=0;r<2;r++){if(t[r]<n[r])return-1;if(t[r]>n[r])return 1}return 0},t.isPrivateIP=t=>null!=(t=t.toString()).match(/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^172\.16\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^fc00:/)||null!=t.match(/^fe80:/),t.ntoa4=t=>t=((t=t.toString())>>>24&255)+'.'+(t>>>16&255)+'.'+(t>>>8&255)+'.'+(255&t),t.ntoa6=t=>{let n='[';for(let r=0;r<t.length;r++)n+=(t[r]>>>16).toString(16)+':',n+=(65535&t[r]).toString(16)+':';return n=n.replace(/:$/,']').replace(/:0+/g,':').replace(/::+/,'::'),n};
|
package/package.json
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "geoip-lite2",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "A light weight native JavaScript implementation of GeoIP API from MaxMind.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"city",
|
|
7
|
-
"country",
|
|
8
|
-
"fast-geoip",
|
|
9
|
-
"geo",
|
|
10
|
-
"geoip",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"minify-linux": "echo \"Please wait...\n\" && bash _Minify/linux.bash",
|
|
52
|
-
"minify-win": "powershell.exe -ExecutionPolicy Bypass .\\_Minify\\windows.ps1",
|
|
53
|
-
"test": "jest test",
|
|
54
|
-
"up": "ncu -u -x chalk && npm install && npm update && npm audit fix",
|
|
55
|
-
"updatedb": "node utils/updatedb.js",
|
|
56
|
-
"updatedb-debug": "node utils/updatedb.js debug",
|
|
57
|
-
"updatedb-force": "node utils/updatedb.js force",
|
|
58
|
-
"version": "node test/version.js"
|
|
59
|
-
},
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"adm-zip": "^0.5.10",
|
|
62
|
-
"async": "^3.2.4",
|
|
63
|
-
"chalk": "4.1.2",
|
|
64
|
-
"iconv-lite": "0.6.3",
|
|
65
|
-
"ip-address": "^8.1.0",
|
|
66
|
-
"lazy": "1.0.11",
|
|
67
|
-
"rimraf": "^5.0.1"
|
|
68
|
-
},
|
|
69
|
-
"devDependencies": {
|
|
70
|
-
"eslint": "^8.
|
|
71
|
-
"jest": "^29.7.0",
|
|
72
|
-
"terser": "^5.
|
|
73
|
-
},
|
|
74
|
-
"engines": {
|
|
75
|
-
"node": ">=5.10.0"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "geoip-lite2",
|
|
3
|
+
"version": "2.1.8",
|
|
4
|
+
"description": "A light weight native JavaScript implementation of GeoIP API from MaxMind.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"city",
|
|
7
|
+
"country",
|
|
8
|
+
"fast-geoip",
|
|
9
|
+
"geo",
|
|
10
|
+
"geoip",
|
|
11
|
+
"geoip-api",
|
|
12
|
+
"geolite",
|
|
13
|
+
"geolite2",
|
|
14
|
+
"geolocation",
|
|
15
|
+
"geolookup",
|
|
16
|
+
"ip",
|
|
17
|
+
"ipv4",
|
|
18
|
+
"ipv6",
|
|
19
|
+
"location",
|
|
20
|
+
"maxmind",
|
|
21
|
+
"region",
|
|
22
|
+
"state"
|
|
23
|
+
],
|
|
24
|
+
"homepage": "https://github.com/sefinek24/geoip-lite2#readme",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/sefinek24/geoip-lite2/issues"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/sefinek24/geoip-lite2.git"
|
|
31
|
+
},
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"author": "Philip Tellis <philip@bluesmoon.info> (https://bluesmoon.info)",
|
|
34
|
+
"main": "lib/geoip.js",
|
|
35
|
+
"types": "index.d.ts",
|
|
36
|
+
"directories": {
|
|
37
|
+
"lib": "lib",
|
|
38
|
+
"test": "test"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"data/",
|
|
42
|
+
"lib/",
|
|
43
|
+
"test/",
|
|
44
|
+
"utils/",
|
|
45
|
+
".gitignore",
|
|
46
|
+
"AUTHORS",
|
|
47
|
+
"index.d.ts",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
],
|
|
50
|
+
"scripts": {
|
|
51
|
+
"minify-linux": "echo \"Please wait...\n\" && bash _Minify/linux.bash",
|
|
52
|
+
"minify-win": "powershell.exe -ExecutionPolicy Bypass .\\_Minify\\windows.ps1",
|
|
53
|
+
"test": "jest test",
|
|
54
|
+
"up": "ncu -u -x chalk && npm install && npm update && npm audit fix",
|
|
55
|
+
"updatedb": "node utils/updatedb.js",
|
|
56
|
+
"updatedb-debug": "node utils/updatedb.js debug",
|
|
57
|
+
"updatedb-force": "node utils/updatedb.js force",
|
|
58
|
+
"version": "node test/version.js"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"adm-zip": "^0.5.10",
|
|
62
|
+
"async": "^3.2.4",
|
|
63
|
+
"chalk": "4.1.2",
|
|
64
|
+
"iconv-lite": "0.6.3",
|
|
65
|
+
"ip-address": "^8.1.0",
|
|
66
|
+
"lazy": "1.0.11",
|
|
67
|
+
"rimraf": "^5.0.1"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"eslint": "^8.50.0",
|
|
71
|
+
"jest": "^29.7.0",
|
|
72
|
+
"terser": "^5.20.0"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=5.10.0"
|
|
76
|
+
}
|
|
77
|
+
}
|
package/utils/updatedb.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';const{name:e,version:t}=require('../package.json'),n=`Mozilla/5.0 (compatible; ${e}/${t}; +https://sefinek.net)`,o=require('node:fs'),r=require('node:http'),s=require('node:https'),i=require('node:path'),c=require('node:url'),
|
|
1
|
+
'use strict';const{name:e,version:t}=require('../package.json'),n=`Mozilla/5.0 (compatible; ${e}/${t}; +https://sefinek.net)`,o=require('node:fs'),r=require('node:http'),s=require('node:https'),i=require('node:path'),c=require('node:url'),a=require('node:zlib');o.existsSync=o.existsSync||i.existsSync;const l=require('async'),d=require('chalk'),u=require('iconv-lite'),p=require('lazy'),f=require('rimraf').sync,g=require('adm-zip'),m=require('../lib/utils.js'),{Address6:h,Address4:y}=require('ip-address'),w=process.argv.slice(2);let S=w.find((function(e){return null!==e.match(/^license_key=[a-zA-Z0-9]+/)}));void 0===S&&void 0!==process.env.LICENSE_KEY&&(S='license_key='+process.env.LICENSE_KEY);let v=w.find((function(e){return null!==e.match(/^geoDataDir=[\w./]+/)}));void 0===v&&void 0!==process.env.GEODATADIR&&(v='geoDataDir='+process.env.GEODATADIR);let x=i.resolve(__dirname,'..','data');void 0!==v&&(x=i.resolve(process.cwd(),v.split('=')[1]),o.existsSync(x)||(console.log(d.red('ERROR')+': Directory doesn\'t exist: '+x),process.exit(1)));const E=i.resolve(__dirname,'..','tmp'),k={},I={},C=[{type:'country',url:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&'+S,checksum:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip.sha256&'+S,fileName:'GeoLite2-Country-CSV.zip',src:['GeoLite2-Country-Locations-en.csv','GeoLite2-Country-Blocks-IPv4.csv','GeoLite2-Country-Blocks-IPv6.csv'],dest:['','geoip-country.dat','geoip-country6.dat']},{type:'city',url:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip&'+S,checksum:'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip.sha256&'+S,fileName:'GeoLite2-City-CSV.zip',src:['GeoLite2-City-Locations-en.csv','GeoLite2-City-Blocks-IPv4.csv','GeoLite2-City-Blocks-IPv6.csv'],dest:['geoip-city-names.dat','geoip-city.dat','geoip-city6.dat']}];function D(e){const t=i.dirname(e);o.existsSync(t)||o.mkdirSync(t)}function R(e){const t=/^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/;if(!t.test(e)&&(e=function(e){let t=0,n=-1;for(e=e.replace(/""/,'\\"').replace(/'/g,'\\\'');t<e.length&&n<e.length;)t=n,n=e.indexOf(',',t+1),n<0&&(n=e.length),e.indexOf('\'',t||0)>-1&&e.indexOf('\'',t)<n&&'"'!=e[t+1]&&'"'!=e[n-1]&&(n=(e=e.substr(0,t+1)+'"'+e.substr(t+1,n-t-1)+'"'+e.substr(n,e.length-n)).indexOf(',',n+1),n<0&&(n=e.length));return e}(e),!t.test(e)))return null;const n=[];return e.replace(/(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g,(function(e,t,o,r){return void 0!==t?n.push(t.replace(/\\'/g,'\'')):void 0!==o?n.push(o.replace(/\\"/g,'"').replace(/\\'/g,'\'')):void 0!==r&&n.push(r),''})),/,\s*$/.test(e)&&n.push(''),n}function B(e){const t=c.parse(e);if(t.headers={'User-Agent':n},process.env.http_proxy||process.env.https_proxy)try{const e=require('node:https-proxy-agent');t.agent=new e(process.env.http_proxy||process.env.https_proxy)}catch(e){console.error('Install https-proxy-agent to use an HTTP/HTTPS proxy'),process.exit(-1)}return t}function _(e,t){if(-1!==w.indexOf('force'))return t(null,e);const n=e.checksum;if(void 0===n)return t(null,e);o.readFile(i.join(x,e.type+'.checksum'),{encoding:'utf8'},(function(o,i){!o&&i&&i.length&&(e.checkValue=i),console.log('Checking ',e.fileName);var c=s.get(B(n),(function(n){const o=n.statusCode;200!==o&&(console.error(d.red('ERROR')+n.data),console.error(d.red('ERROR')+': HTTP Request Failed [%d %s]',o,r.STATUS_CODES[o]),c.end(),process.exit(1));let s='';n.on('data',(function(e){s+=e})),n.on('end',(()=>{s&&s.length?s===e.checkValue?(console.log(d.green('Database "'+e.type+'" is up to date')),e.skip=!0):(console.log(d.green('Database '+e.type+' has new data')),e.checkValue=s):(console.error(d.red('ERROR')+': Could not retrieve checksum for',e.type,d.red('Aborting')),console.error('Run with "force" to update without checksum'),c.end(),process.exit(1)),t(null,e)}))}))}))}function b(e,t){if(e.skip)return t(null,null,null,e);const n=e.url;let c=e.fileName;const l='.gz'===i.extname(c);l&&(c=c.replace('.gz',''));const u=i.join(E,c);if(o.existsSync(u))return t(null,u,c,e);console.log('Fetching ',c),D(u);var p=s.get(B(n),(function(n){const s=n.statusCode;let i;200!==s&&(console.error(d.red('ERROR')+': HTTP Request Failed [%d %s]',s,r.STATUS_CODES[s]),p.end(),process.exit(1));const f=o.createWriteStream(u);i=l?n.pipe(a.createGunzip()).pipe(f):n.pipe(f),i.on('close',(()=>{console.log(d.green(' DONE')),t(null,u,c,e)}))}));process.stdout.write('Retrieving '+c+'...')}function A(e,t,n,r){if(n.skip)return r(null,n);if('.zip'!==i.extname(t))r(null,n);else{process.stdout.write('Extracting '+t+'...');new g(e).getEntries().forEach((e=>{if(e.isDirectory)return;const t=e.entryName.split('/'),n=t[t.length-1],r=i.join(E,n);o.writeFileSync(r,e.getData())})),console.log(d.green(' DONE')),r(null,n)}}function O(e,t,n){let r=0;const s=i.join(x,t),c=i.join(E,e);f(s),D(s),process.stdout.write('Processing data (may take a moment)...');var a=Date.now(),l=o.openSync(s,'w');p(o.createReadStream(c)).lines.map((e=>u.decode(e,'latin1'))).skip(1).map((function(e){const t=R(e);if(!t||t.length<6)return void console.warn('weird line: %s::',e);let n,s,i;r++;const c=k[t[1]];let d,u,p;if(c){if(t[0].match(/:/)){for(u=34,i=new h(t[0]),n=m.aton6(i.startAddress().correctForm()),s=m.aton6(i.endAddress().correctForm()),d=Buffer.alloc(u),p=0;p<n.length;p++)d.writeUInt32BE(n[p],4*p);for(p=0;p<s.length;p++)d.writeUInt32BE(s[p],16+4*p)}else u=10,i=new y(t[0]),n=parseInt(i.startAddress().bigInteger(),10),s=parseInt(i.endAddress().bigInteger(),10),d=Buffer.alloc(u),d.fill(0),d.writeUInt32BE(n,0),d.writeUInt32BE(s,4);d.write(c,u-2),o.writeSync(l,d,0,u,null),Date.now()-a>5e3&&(a=Date.now(),process.stdout.write('\nStill working ('+r+')...'))}})).on('pipe',(()=>{console.log(d.green(' DONE')),n()}))}function q(e,t,n){let r=0;const s=i.join(x,t),c=i.join(E,e);f(s),process.stdout.write('Processing data (may take a moment) ...');var a=Date.now(),l=o.openSync(s,'w');p(o.createReadStream(c)).lines.map((e=>u.decode(e,'latin1'))).skip(1).map((function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=R(e);if(!t)return void console.warn('Weird line: %s::',e);let n,s,i,c,d,u,p,f,g,w;if(r++,t[0].match(/:/)){let e=0;for(u=48,i=new h(t[0]),n=m.aton6(i.startAddress().correctForm()),s=m.aton6(i.endAddress().correctForm()),c=parseInt(t[1],10),c=I[c],d=Buffer.alloc(u),d.fill(0),w=0;w<n.length;w++)d.writeUInt32BE(n[w],e),e+=4;for(w=0;w<s.length;w++)d.writeUInt32BE(s[w],e),e+=4;d.writeUInt32BE(c>>>0,32),p=Math.round(1e4*parseFloat(t[7])),f=Math.round(1e4*parseFloat(t[8])),g=parseInt(t[9],10),d.writeInt32BE(p,36),d.writeInt32BE(f,40),d.writeInt32BE(g,44)}else u=24,i=new y(t[0]),n=parseInt(i.startAddress().bigInteger(),10),s=parseInt(i.endAddress().bigInteger(),10),c=parseInt(t[1],10),c=I[c],d=Buffer.alloc(u),d.fill(0),d.writeUInt32BE(n>>>0,0),d.writeUInt32BE(s>>>0,4),d.writeUInt32BE(c>>>0,8),p=Math.round(1e4*parseFloat(t[7])),f=Math.round(1e4*parseFloat(t[8])),g=parseInt(t[9],10),d.writeInt32BE(p,12),d.writeInt32BE(f,16),d.writeInt32BE(g,20);o.writeSync(l,d,0,d.length,null),Date.now()-a>5e3&&(a=Date.now(),process.stdout.write('\nStill working ('+r+')...'))})).on('pipe',n)}function L(e,t){if(e.skip)return t(null,e);const n=e.type,r=e.src,s=e.dest;'country'===n?Array.isArray(r)?function(e,t){const n=i.join(E,e);process.stdout.write('Processing Lookup Data (may take a moment)...'),p(o.createReadStream(n)).lines.map((e=>u.decode(e,'latin1'))).skip(1).map((function(e){const t=R(e);!t||t.length<6?console.log('weird line: %s::',e):k[t[0]]=t[4]})).on('pipe',(()=>{console.log(d.green(' DONE')),t()}))}(r[0],(()=>{O(r[1],s[1],(()=>{O(r[2],s[2],(()=>{t(null,e)}))}))})):O(r,s,(()=>{t(null,e)})):'city'===n&&function(e,t,n){let r=null,s=0;const c=i.join(x,t),a=i.join(E,e);f(c);var l=o.openSync(c,'w');p(o.createReadStream(a)).lines.map((e=>u.decode(e,'utf-8'))).skip(1).map((function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=Buffer.alloc(88),n=R(e);if(!n)return void console.warn('Weird line: %s::',e);r=parseInt(n[0]),I[r]=s;const i=n[4],c=n[6],a=n[10],d=parseInt(n[11]),u=n[12],p=n[13];t.fill(0),t.write(i,0),t.write(c,2),d&&t.writeInt32BE(d,5),t.write(p,9),t.write(u,10),t.write(a,42),o.writeSync(l,t,0,t.length,null),s++})).on('pipe',n)}(r[0],s[0],(()=>{q(r[1],s[1],(()=>{console.log('city data processed'),q(r[2],s[2],(()=>{console.log(d.green(' DONE')),t(null,e)}))}))}))}function F(e,t){if(e.skip||!e.checkValue)return t();o.writeFile(i.join(x,e.type+'.checksum'),e.checkValue,'utf8',(function(n){n&&console.log(d.red('Failed to Update checksums.'),'Database:',e.type),t()}))}S||(console.error(d.red('ERROR')+': Missing license_key'),process.exit(1)),D(E),l.eachSeries(C,((e,t)=>{l.seq(_,b,A,L,F)(e,t)}),(e=>{e?(console.error(d.red('Failed to update databases from MaxMind.'),e),process.exit(1)):(console.log(d.green('Successfully updated databases from MaxMind.')),-1!==w.indexOf('debug')?console.debug(d.blue.bold('Notice: temporary files are not deleted for debug purposes.')):f(E),process.exit(0))}));
|