IP2Location Node.js API#

IP2Location Class#

class IP2Location#

Construct the IP2Location Class.

open(binPath)#

Load the IP2Location BIN database for lookup.

Parameters:

binPath (str) – (Required) The file path links to IP2Location BIN databases.

openAsync(binPath)#

Load the IP2Location BIN database for lookup asynchronously.

Parameters:

binPath (str) – (Required) The file path links to IP2Location BIN databases.

getAll(ipAddress)#

Retrieve geolocation information for an IP address.

Parameters:

ipAddress (str) – (Required) The IP address (IPv4 or IPv6).

Returns:

Returns the geolocation information in array. Refer below table for the fields avaliable in the array

Return type:

array

RETURN FIELDS

Field Name

Description

countryShort

Two-character country code based on ISO 3166.

countryLong

Country name based on ISO 3166.

region

Region or state name.

city

City name.

isp

Internet Service Provider or company’s name.

latitude

City latitude. Defaults to capital city latitude if city is unknown.

longitude

City longitude. Defaults to capital city longitude if city is unknown.

domain

Internet domain name associated with IP address range.

zipCode

ZIP code or Postal code. 172 countries supported.

timeZone

UTC time zone (with DST supported).

netSpeed

Internet connection type.

iddCode

The IDD prefix to call the city from another country.

areaCode

A varying length number assigned to geographic areas for calls between cities. 223 countries supported.

weatherStationCode

The special code to identify the nearest weather observation station.

weatherStationName

The name of the nearest weather observation station.

mcc

Mobile Country Codes (MCC) as defined in ITU E.212 for use in identifying mobile stations in wireless telephone networks, particularly GSM and UMTS networks.

mnc

Mobile Network Code (MNC) is used in combination with a Mobile Country Code(MCC) to uniquely identify a mobile phone operator or carrier.

mobileBrand

Commercial brand associated with the mobile carrier. You may click mobile carrier coverage to view the coverage report.

elevation

Average height of city above sea level in meters (m).

usageType

Usage type classification of ISP or company.

addressType

IP address types as defined in Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6).

category

The domain category based on IAB Tech Lab Content Taxonomy.

district

District or county name.

asn

Autonomous system number (ASN). BIN databases.

as

Autonomous system (AS) name.

getAllAsync(ipAddress)#

Retrieve geolocation information for an IP address asynchronously.

Parameters:

ipAddress (str) – (Required) The IP address (IPv4 or IPv6).

Returns:

Returns the geolocation information in a Promise of an array. Refer below table for the fields avaliable in the array

Return type:

Promise of an array

RETURN FIELDS

Field Name

Description

countryShort

Two-character country code based on ISO 3166.

countryLong

Country name based on ISO 3166.

region

Region or state name.

city

City name.

isp

Internet Service Provider or company’s name.

latitude

City latitude. Defaults to capital city latitude if city is unknown.

longitude

City longitude. Defaults to capital city longitude if city is unknown.

domain

Internet domain name associated with IP address range.

zipCode

ZIP code or Postal code. 172 countries supported.

timeZone

UTC time zone (with DST supported).

netSpeed

Internet connection type.

iddCode

The IDD prefix to call the city from another country.

areaCode

A varying length number assigned to geographic areas for calls between cities. 223 countries supported.

weatherStationCode

The special code to identify the nearest weather observation station.

weatherStationName

The name of the nearest weather observation station.

mcc

Mobile Country Codes (MCC) as defined in ITU E.212 for use in identifying mobile stations in wireless telephone networks, particularly GSM and UMTS networks.

mnc

Mobile Network Code (MNC) is used in combination with a Mobile Country Code(MCC) to uniquely identify a mobile phone operator or carrier.

mobileBrand

Commercial brand associated with the mobile carrier. You may click mobile carrier coverage to view the coverage report.

elevation

Average height of city above sea level in meters (m).

usageType

Usage type classification of ISP or company.

addressType

IP address types as defined in Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6).

category

The domain category based on IAB Tech Lab Content Taxonomy.

district

District or county name.

asn

Autonomous system number (ASN). BIN databases.

as

Autonomous system (AS) name.

IPTools Class#

class IPTools#

Initiate IPTools class.

isIPV4(ipAddress)#

Verify if a string is a valid IPv4 address.

Parameters:

ipAddress (str) – (Required) IP address.

Returns:

Return True if the IP address is a valid IPv4 address or False if it isn’t a valid IPv4 address.

Return type:

boolean

isIPV6(ipAddress)#

Verify if a string is a valid IPv6 address

Parameters:

ipAddress (str) – (Required) IP address.

Returns:

Return True if the IP address is a valid IPv6 address or False if it isn’t a valid IPv6 address.

Return type:

boolean

ipV4ToDecimal(ipAddress)#

Translate IPv4 address from dotted-decimal address to decimal format.

Parameters:

ipAddress (str) – (Required) IPv4 address.

Returns:

Return the decimal format of the IPv4 address.

Return type:

int

decimalToIPV4(ipNumber)#

Translate IPv4 address from decimal number to dotted-decimal address.

Parameters:

ip_number (str) – (Required) Decimal format of the IPv4 address.

Returns:

Returns the dotted-decimal format of the IPv4 address.

Return type:

string

ipV6ToDecimal(ipAddress)#

Translate IPv6 address from hexadecimal address to decimal format.

Parameters:

ipAddress (str) – (Required) IPv6 address.

Returns:

Return the decimal format of the IPv6 address.

Return type:

int

decimalToIPV6(ipNumber)#

Translate IPv6 address from decimal number into hexadecimal address.

Parameters:

ip_number (str) – (Required) Decimal format of the IPv6 address.

Returns:

Returns the hexadecimal format of the IPv6 address.

Return type:

string

ipV4ToCIDR(ip_from, ip_to)#

Convert IPv4 range into a list of IPv4 CIDR notation.

Parameters:
  • ip_from (str) – (Required) The starting IPv4 address in the range.

  • ip_to (str) – (Required) The ending IPv4 address in the range.

Returns:

Returns the list of IPv4 CIDR notation.

Return type:

array

cidrToIPV4(cidr)#

Convert IPv4 CIDR notation into a list of IPv4 addresses.

Parameters:

cidr (str) – (Required) IPv4 CIDR notation.

Returns:

Returns an list of IPv4 addresses.

Return type:

array

ipV6ToCIDR(ip_from, ip_to)#

Convert IPv6 range into a list of IPv6 CIDR notation.

Parameters:
  • ip_from (str) – (Required) The starting IPv6 address in the range.

  • ip_to (str) – (Required) The ending IPv6 address in the range.

Returns:

Returns the list of IPv6 CIDR notation.

Return type:

array

cidrToIPV6(cidr)#

Convert IPv6 CIDR notation into a list of IPv6 addresses.

Parameters:

cidr (str) – (Required) IPv6 CIDR notation.

Returns:

Returns an list of IPv6 addresses.

Return type:

array

compressIPV6(ipAddress)#

Compress a IPv6 to shorten the length.

Parameters:

ipAddress (str) – (Required) IPv6 address.

Returns:

Returns the compressed version of IPv6 address.

Return type:

str

expandIPV6(ipAddress)#

Expand a shorten IPv6 to full length.

Parameters:

ipAddress (str) – (Required) IPv6 address.

Returns:

Returns the extended version of IPv6 address.

Return type:

str

Country Class#

class Country(csvFilePath)#

Initiate Ip2locationCountry class and load the IP2Location Country Information CSV file. This database is free for download at https://www.ip2location.com/free/country-information.

Parameters:

csvFilePath (str) – (Required) The file path links to IP2Location Country Information CSV file.

getCountryInfo(countryCode)#

Provide a ISO 3166 country code to get the country information in array. Will return a full list of countries information if country code not provided.

Parameters:

countryCode (str) – (Required) The ISO 3166 country code of a country.

Returns:

Returns the country information in array. Refer below table for the fields avaliable in the array.

Return type:

array

RETURN FIELDS

Field Name

Description

countryCode

Two-character country code based on ISO 3166.

countryAlpha3Code

Three-character country code based on ISO 3166.

countryNumericCode

Three-character country code based on ISO 3166.

capital

Capital of the country.

countryDemonym

Demonym of the country.

totalArea

Total area in km2.

population

Population of year 2014.

idd_code

The IDD prefix to call the city from another country.

currencyCode

Currency code based on ISO 4217.

currencyName

Currency name.

currencySymbol

Currency symbol.

langCode

Language code based on ISO 639.

langName

Language name.

cctld

Country-Code Top-Level Domain.

Region Class#

class Region(csvFilePath)#

Initiate Ip2locationRegion class and load the IP2Location ISO 3166-2 Subdivision Code CSV file. This database is free for download at https://www.ip2location.com/free/iso3166-2

Parameters:

csvFilePath (str) – (Required) The file path links to IP2Location ISO 3166-2 Subdivision Code CSV file.

getRegionCode(countryCode, regionName)#

Provide a ISO 3166 country code and the region name to get ISO 3166-2 subdivision code for the region.

Parameters:
  • countryCode (str) – (Required) Two-character country code based on ISO 3166.

  • regionName (str) – (Required) Region or state name.

Returns:

Returns the ISO 3166-2 subdivision code of the region.

Return type:

str