IP2Location OCaml API
Database Module
- open_db(bin_path)
Open and load the IP2Location BIN database for lookup.
- Parameters:
bin_path (str) – (Required) The file path links to IP2Location BIN databases.
- close_db()
Closes BIN file and resets metadata.
- query(ip)
Retrieve geolocation information for an IP address.
- Parameters:
ip (str) – (Required) The IP address (IPv4 or IPv6).
- Returns:
Returns the geolocation information. Refer below table for the fields avaliable.
RETURN FIELDS
Field Name
Description
country_short
Two-character country code based on ISO 3166.
country_long
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.
zip_code
ZIP code or Postal code. 172 countries supported.
time_zone
UTC time zone (with DST supported).
net_speed
Internet connection type.
idd_code
The IDD prefix to call the city from another country.
area_code
A varying length number assigned to geographic areas for calls between cities. 223 countries supported.
weather_station_code
The special code to identify the nearest weather observation station.
weather_station_name
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.
mobile_brand
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).
usage_type
Usage type classification of ISP or company.
address_type
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.
asys
Autonomous system (AS) name.