IP2Location Kotlin API
IP2Location Class
- class IP2Location
Initiate the IP2Location class.
- open(dbPath)
Open and load the IP2Location BIN database for lookup.
- Parameters:
dbPath (str) – (Required) The file path links to IP2Location BIN databases.
- close()
Closes BIN file and resets metadata.
- ipQuery(strIPAddress)
Retrieve geolocation information for an IP address.
- Parameters:
strIPAddress (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
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.
status
Status code of query.
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
- Country(CSVFile)
Load the IP2Location Country Information CSV file. This database is free for download at https://www.ip2location.com/free/country-information.
- Parameters:
CSVFile (String) – (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 (String) – (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
Region Class
- Region(CSVFile)
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:
CSVFile (String) – (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 (String) – (Required) Two-character country code based on ISO 3166.
RegionName (String) – (Required) Region or state name.
- Returns:
Returns the ISO 3166-2 subdivision code of the region.
- Return type:
String