IP2Location .NET API#

Component Class#

Open(DBPath, UseMMF)#

Open and load the IP2Location BIN database for lookup.

Parameters:
  • DBPath (String) – (Required) The file path links to IP2Location BIN databases.

  • UseMMF (Boolean) – (Optional) Specify whether to use MemoryMappedFile then preload BIN file or not. Default is False.

Open(DBStream)#

Initialize component with a stream that contains the BIN database then preload BIN file.

Parameters:

DBStream (Stream) – (Required) A stream that contains the BIN database.

Close()#

Closes BIN file and resets metadata.

IPQuery(_IPAddress)#

Retrieve geolocation information for an IP address.

Parameters:

_IPAddress (String) – (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.

InternetServiceProvider

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.

DomainName

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.

IPQueryAsync(_IPAddress)#

Query IP address asynchronously.

Parameters:

_IPAddress (String) – (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.

InternetServiceProvider

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.

DomainName

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(IP)#

Verify if a string is a valid IPv4 address.

Parameters:

IP (String) – (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(IP)#

Verify if a string is a valid IPv6 address

Parameters:

IP (String) – (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(IP)#

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

Parameters:

IP (String) – (Required) IPv4 address.

Returns:

Return the decimal format of the IPv4 address.

Return type:

BigInteger

DecimalToIPv4(IPNum)#

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

Parameters:

IPNum (String) – (Required) Decimal format of the IPv4 address.

Returns:

Returns the dotted-decimal format of the IPv4 address.

Return type:

String

IPv6ToDecimal(IP)#

Translate IPv6 address from hexadecimal address to decimal format.

Parameters:

IP (String) – (Required) IPv6 address.

Returns:

Return the decimal format of the IPv6 address.

Return type:

BigInteger

DecimalToIPv6(IPNum)#

Translate IPv6 address from decimal number into hexadecimal address.

Parameters:

IPNum (String) – (Required) Decimal format of the IPv6 address.

Returns:

Returns the hexadecimal format of the IPv6 address.

Return type:

String

IPv4ToCIDR(IPFrom, IPTo)#

Convert IPv4 range into a list of IPv4 CIDR notation.

Parameters:
  • IPFrom (String) – (Required) The starting IPv4 address in the range.

  • IPTo (String) – (Required) The ending IPv4 address in the range.

Returns:

Returns the list of IPv4 CIDR notation.

Return type:

List

CIDRToIPv4(CIDR)#

Convert IPv4 CIDR notation into a list of IPv4 addresses.

Parameters:

CIDR (String) – (Required) IPv4 CIDR notation.

Returns:

Returns an list of IPv4 addresses.

Return type:

List

IPv6ToCIDR(IPFrom, IPTo)#

Convert IPv6 range into a list of IPv6 CIDR notation.

Parameters:
  • IPFrom (String) – (Required) The starting IPv6 address in the range.

  • IPTo (String) – (Required) The ending IPv6 address in the range.

Returns:

Returns the list of IPv6 CIDR notation.

Return type:

List

CIDRToIPv6(CIDR)#

Convert IPv6 CIDR notation into a list of IPv6 addresses.

Parameters:

CIDR (String) – (Required) IPv6 CIDR notation.

Returns:

Returns an list of IPv6 addresses.

Return type:

List

CompressIPv6(IP)#

Compress a IPv6 to shorten the length.

Parameters:

IP (String) – (Required) IPv6 address.

Returns:

Returns the compressed version of IPv6 address.

Return type:

String

ExpandIPv6(IP)#

Expand a shorten IPv6 to full length.

Parameters:

IP (String) – (Required) IPv6 address.

Returns:

Returns the extended version of IPv6 address.

Return type:

String

Country Class#

class Country(CSVFile)#

Initiate Country class and 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 List. Refer below table for the fields avaliable in the List.

Return type:

List

RETURN FIELDS

Field Name

Description

country_code

Two-character country code based on ISO 3166.

country_alpha3_code

Three-character country code based on ISO 3166.

country_numeric_code

Three-character country code based on ISO 3166.

capital

Capital of the country.

country_demonym

Demonym of the country.

total_area

Total area in km2.

population

Population of year 2014.

idd_code

The IDD prefix to call the city from another country.

currency_code

Currency code based on ISO 4217.

currency_name

Currency name.

currency_symbol

Currency symbol.

lang_code

Language code based on ISO 639.

lang_name

Language name.

cctld

Country-Code Top-Level Domain.

Region Class#

class Region(CSVFile)#

Initiate Region 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:

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