Why the MMDB database does not include the IP range fields?

MMDB files are designed to provide IP information in a singular direction.

If you take a look at our MMDB files, you might notice that we do not provide the start_ip, end_ip and the optional join_key fields like we do for our CSV and JSON file formats.

Although we do provide the range field that includes the start_ip and end_ip information in the CIDR format. For example, in the example below range value “13.107.48.0/22” is the same as Start IP → 13.107.48.0 and End IP → 13.107.51.255. The data is provided in the CIDR range format.

The join_key is a special IP range field that facilitates efficient IP lookups in some DBMS platforms like Snowflake. The join_key does not add value to the MMDB file format.

Why don’t we provide those three fields?

MMDB file format is a special type of database format that is designed for one thing only — efficient IP address to IP information lookups. It can not provide support for reverse IP lookup operations such as city → IP ranges, ASN→ IP ranges etc. It is a singular path lookup file in a binary format.

The start_ip and end_ip information in the MMDB file format is essentially embedded in the binary context. When you look up an IP address using a specialized tool (like our mmdbctl tool) that can read the MMDB binary file, input IP addresses are matched to the embedded IP range fields.

However, if you need the start_ip and end_ip information, you can still get information from the MMDB file database in the form of the range field (e.g. 1.188.0.0/16)

Is there a way to get the start_ip and end_ip information in the MMDB file?

Yes.

For that, you can download the CSV file format of the database or use the mmdbctl tool to export the MMDB file to a CSV file (link to documentation).

Then you compile/import the CSV database to the MMDB database with the mmdbctl’s import command (link to documentation), like so:

mmdbctl import ip_company_sample.csv ip_company_sample.mmdb

You will find a network field that combines the start_ip and end_ip values in the IP range format (e.g. 12.0.136.200-12.0.136.207).

If you want to keep the start_ip and end_ip columns as separate columns, duplicate the start_ip and end_ip columns in the CSV file. Rename the duplicated start_ip column to start_ip_range and end_ip column to end_ip_range.

Then, you compile/import the CSV database to the MMDB database with the mmdbctl’s import command (link to documentation).

mmdbctl import ip_company_sample_range.csv ip_company_sample_range.mmdb

mmdbctl read -f json-pretty 122.54.164.0 ip_company_sample_range.mmdb
{
  "as_domain": "pldt.com",
  "as_name": "Philippine Long Distance Telephone Company",
  "as_type": "isp",
  "asn": "AS9299",
  "country": "PH",
  "domain": "pldt.com",
  "end_ip_range": "122.54.164.7",
  "name": "IPG",
  "network": "122.54.164.0-122.54.164.7",
  "start_ip_range": "122.54.164.0",
  "type": "isp"
}

Even though the IP range level is not often needed for using the MMDB database, we provide the range field to provide context around the IP address. To further customize the MMDB database, you are always welcome to use the open source mmdbctl tool, or you can request us to set you up with a custom IP dataset.