fast-iptocountry
Node.JS module for getting GeoLocation for a given IP address focused on performance. It uses database from http://software77.net/geo-ip/ , which is a Donationware (read more here: http://software77.net/geo-ip/?license ) .
Installation
`npm install --save fast-iptocountry
Description
This module downloads a CSV database of IP to Country mapping (~12MB) from http://software77.net/geo-ip/ and converts it into a more useful format (~10MB) that allows for a quick binary search. It will require about 21MB of disk space and about 80MB of memory.
Usage
// you must pass a directory in which database will be saved// if it doesn't exist, it will be createdconst iptocountry = "cache/"; // check when the database was updated// t are days// t is Infinity if there's no database at alliptocountry var arr = '50.21.180.100' '50.22.180.100' '1.38.1.1' 2733834241 '8.8.8.8' '127.0.0.1' 'asd'; // ready event is emitted when the database has been loadediptocountry;
Result of this sample script:
50.21.180.100 - { code: 'US', country: 'United States' }
50.22.180.100 - { code: 'US', country: 'United States' }
1.38.1.1 - { code: 'IN', country: 'India' }
2733834241 '-' { code: 'US', country: 'United States' }
8.8.8.8 - { code: 'US', country: 'United States' }
127.0.0.1 - { code: 'ZZ', country: 'Reserved' }
asd - { code: 'ZZ', country: 'Reserved' }
TODO
- IPv6 not even tested...
- Memory usage is high
- Benchmarking
- Proper tests