8.1.3 • Published 5 years ago

async-ip2location v8.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Asynchronous IP2Location Node.js Module

This Node.js module provides a fast and asynchronous lookup of country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, and usage type from IP address by using IP2Location database. This module uses a file based database available at IP2Location.com. This database simply contains IP blocks as keys, and other information such as country, region, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection type, IDD code, area code, weather station code, station name, mcc, mnc, mobile brand, elevation, and usage type as values. It supports both IP address in IPv4 and IPv6.

This module can be used in many types of projects such as:

  • select the geographically closest mirror
  • analyze your web server logs to determine the countries of your visitors
  • credit card fraud detection
  • software export controls
  • display native language and currency
  • prevent password sharing and abuse of service
  • geotargeting in advertisement

The database will be updated in monthly basis for the greater accuracy. Free sample DB1 database is available at /samples directory or download it from https://www.ip2location.com/developers.htm.

The complete database is available at https://www.ip2location.com under Premium subscription package.

Dependencies

This library requires IP2Location BIN data file to function. You may download the BIN data file at

IPv4 BIN vs IPv6 BIN

Use the IPv4 BIN file if you just need to query IPv4 addresses. If you query an IPv6 address using the IPv4 BIN, you'll see the IPV6_NOT_SUPPORTED error.

Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.

Methods

The module itself only exports a single function that is used to initialize the database. The result is a promise that resolves to a database object with the methods below.

Below are the methods supported in this module.

Method NameDescription
get_allReturns the geolocation information in an object.
get_country_shortReturns the country code.
get_country_longReturns the country name.
get_regionReturns the region name.
get_cityReturns the city name.
get_ispReturns the ISP name.
get_latitudeReturns the latitude.
get_longitudeReturns the longitude.
get_domainReturns the domain name.
get_zipcodeReturns the ZIP code.
get_timezoneReturns the time zone.
get_netspeedReturns the net speed.
get_iddcodeReturns the IDD code.
get_areacodeReturns the area code.
get_weatherstationcodeReturns the weather station code.
get_weatherstationnameReturns the weather station name.
get_mccReturns the mobile country code.
get_mncReturns the mobile network code.
get_mobilebrandReturns the mobile brand.
get_elevationReturns the elevation in meters.
get_usagetypeReturns the usage type.

Usage

var ip2loc = require('./ip2location.js');

ip2loc('./DB8.BIN')
	.then((db) => {
		return db.get_all('8.8.8.8');
	})
	.then(result => {
		console.log(JSON.stringify(result))
		console.log('--------------------------------------------------------------');
	});