ip2location-erlang icon indicating copy to clipboard operation
ip2location-erlang copied to clipboard

Use IP2Location geolocation database to lookup the geolocation information with IP2Location Erlang Module. It can be used to determine country, region, city, coordinates, zip code, time zone, ISP, dom...

IP2Location Erlang Module

This Erlang module provides a fast 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, usage type, address type and IAB category 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, usage type, address type and IAB category 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 LITE databases are available at https://lite.ip2location.com/ upon registration.

The paid databases are available at https://www.ip2location.com under Premium subscription package.

As an alternative, this geolocation module can also call the IP2Location Web Service. This requires an API key. If you don't have an existing API key, you can subscribe for one at the below:

https://www.ip2location.com/web-service/ip2location

Compilation

erlc ip2location.erl
erlc test.erl

QUERY USING THE BIN FILE

Dependencies

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

  • IP2Location LITE BIN Data (Free): https://lite.ip2location.com
  • IP2Location Commercial BIN Data (Comprehensive): https://www.ip2location.com

IPv4 BIN vs IPv6 BIN

Use the IPv4 BIN file if you just need to query IPv4 addresses.

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

Methods

Below are the methods supported in this module.

Method Name Description
new Initialize with the BIN file.
query Returns the geolocation information in an object.
close Closes BIN file and resets metadata.

Usage

test:testme().

QUERY USING THE IP2LOCATION WEB SERVICE

Methods

Below are the methods supported in this module.

Method Name Description
openws 3 input parameters:
  1. IP2Location API Key.
  2. Package (WS1 - WS25)
  3. Use HTTPS or HTTP
lookup Query IP address. This method returns an object containing the geolocation info.
  • country_code
  • country_name
  • region_name
  • city_name
  • latitude
  • longitude
  • zip_code
  • time_zone
  • isp
  • domain
  • net_speed
  • idd_code
  • area_code
  • weather_station_code
  • weather_station_name
  • mcc
  • mnc
  • mobile_brand
  • elevation
  • usage_type
  • address_type
  • category
  • continent
    • name
    • code
    • hemisphere
    • translations
  • country
    • name
    • alpha3_code
    • numeric_code
    • demonym
    • flag
    • capital
    • total_area
    • population
    • currency
      • code
      • name
      • symbol
    • language
      • code
      • name
    • idd_code
    • tld
    • is_eu
    • translations
  • region
    • name
    • code
    • translations
  • city
    • name
    • translations
  • geotargeting
    • metro
  • country_groupings
  • time_zone_info
    • olson
    • current_time
    • gmt_offset
    • is_dst
    • sunrise
    • sunset
    getcredit This method returns the web service credit balance in an object.

    Usage

    test:testme2().