What is maxmind?
The maxmind npm package provides tools for IP geolocation and other related functionalities using MaxMind's GeoIP2 and GeoLite2 databases. It allows developers to determine the geographical location, ISP, and other details of an IP address.
What are maxmind's main functionalities?
IP Geolocation
This feature allows you to determine the geographical location of an IP address. The code sample demonstrates how to use the GeoLite2-City database to get the city information for the IP address '8.8.8.8'.
const maxmind = require('maxmind');
const lookup = async (ip) => {
const cityLookup = await maxmind.open('GeoLite2-City.mmdb');
const city = cityLookup.get(ip);
console.log(city);
};
lookup('8.8.8.8');
ISP Information
This feature allows you to get the ISP information of an IP address. The code sample demonstrates how to use the GeoIP2-ISP database to get the ISP details for the IP address '8.8.8.8'.
const maxmind = require('maxmind');
const lookup = async (ip) => {
const ispLookup = await maxmind.open('GeoIP2-ISP.mmdb');
const isp = ispLookup.get(ip);
console.log(isp);
};
lookup('8.8.8.8');
Anonymous IP Detection
This feature allows you to detect if an IP address is associated with anonymous networks such as VPNs, proxies, or Tor. The code sample demonstrates how to use the GeoIP2-Anonymous-IP database to get anonymous IP details for the IP address '8.8.8.8'.
const maxmind = require('maxmind');
const lookup = async (ip) => {
const anonLookup = await maxmind.open('GeoIP2-Anonymous-IP.mmdb');
const anon = anonLookup.get(ip);
console.log(anon);
};
lookup('8.8.8.8');
Other packages similar to maxmind
ipstack
The ipstack package provides IP geolocation services similar to maxmind. It offers detailed information about the location, currency, timezone, and connection of an IP address. Unlike maxmind, ipstack is a cloud-based service and requires an API key for access.
geoip-lite
The geoip-lite package offers a lightweight IP geolocation solution using a local database. It provides basic geolocation information such as country, region, and city. Compared to maxmind, geoip-lite is less comprehensive but is easier to set up and use for simple geolocation needs.
ipinfo
The ipinfo package provides IP address information including geolocation, ASN, and company details. It uses the IPinfo API and requires an API key. Compared to maxmind, ipinfo offers additional data points such as company information and is also cloud-based.
node-maxmind
IP geo lookup using Maxmind databases, written in pure javascript with no dependencies.
GEO databases
You can download free geo databases here: http://dev.maxmind.com/geoip/geolite.
Installation
npm install maxmind
Main features
- Location lookup
- Country lookup
- Distance between two IP addresses (locations)
- Timezone lookup by IP
- Autonomous System Numbers (ASN) lookup
Usage
** see code samples in ./examples
directory **
City/Location lookup
var maxmind = require('maxmind');
maxmind.init('/path/to/GeoLiteCity.dat');
console.log(maxmind.getLocation("66.6.44.4"));
Country Lookup
var maxmind = require('maxmind');
maxmind.init('/path/to/GeoIP.dat');
console.log(maxmind.getCountry("66.6.44.4"));
Autonomous System Numbers (ASN) lookup
var maxmind = require('maxmind');
maxmind.init('/path/to/GeoIPASNum.dat');
console.log(maxmind.getOrganization("66.6.44.4"));
Caching
By default module does not use cache, and works directly with file system. Enabling cache
leads to better performance, howerver consumer more memory. Currently module supports two options:
indexCache
saves in memory only the country indexmemoryCache
saves in memory full database file
If you decided to enable caching you can pass it as a flag in init
method:
var maxmind = require('maxmind');
maxmind.init('/path/to/GeoIP.dat', { indexCache: true });
Caching could significantly increase performance, refer to this camparison which was made on average
laptop:
- default: 18,000 lookups / second
indexCache
: 80,000 lookups / secondmemodyCache
: 130,000 lookups / second
Tests
If you want ot run tests you will need mocha
installed, then just run it:
$ mocha
Disclaimer
Module is quite young and serious bugs are possible. Feel free to
send pull request / bug reports.