Please read this blog first: How to choose the best file format for your IPinfo database?
The MMDB file format is a special type of binary database, designed for efficient IP lookup and returning its IP metadata information. You pass in an IP address and get its metadata information (geolocation, company, ASN, etc.) back.
In contrast to the binary MMDB database, the CSV and JSON database contain the IP data in plaintext format. You can easily look up the contents of CSV and JSON databases while the MMDB database contains data in binary format.
To read the binary MMDB database file, you need specialized tools such as our mmdbctl tool or MMDB reader libraries.
The columns in these databases
The CSV and JSON files contain IP data in the form of IP ranges. These IP ranges columns are:
- start_ip
- end_ip
- join_key
This IP range column information is converted to binary data within the MMDB file. The MMDB file does not generally return the range information and the join_key
as they are not “IP metadata information”. You get the IP metadata when you look up an IP address from the MMDB.
Consider the IP to Company database:
The CSV file contains 3 IP range columns (including the join_key
) and 8 IP metadata columns containing IP to company information:
# | Field Name | Column Type |
---|---|---|
1 | start_ip | IP Range Columns (1) |
2 | end_ip | IP Range Columns (2) |
3 | join_key | IP Range Columns (3) |
4 | name | IP Metadata Columns (1) |
5 | domain | IP Metadata Columns (2) |
6 | type | IP Metadata Columns (3) |
7 | asn | IP Metadata Columns (4) |
8 | as_name | IP Metadata Columns (5) |
9 | as_domain | IP Metadata Columns (6) |
10 | as_type | IP Metadata Columns (7) |
11 | country | IP Metadata Columns (8) |
It has the same number of columns in the JSON database as well.
How many columns does the MMDB database have?
Let’s use mmdbctl tool to answer that:
Target IP address:
54.38.15.136
Let’s look up the target IP address using the mmdbctl tool:
mmdbctl read 54.38.15.136 company_sample.mmdb
The mmdbctl
tool generally only returns the IP metadata information of the IP address being looked up. Because of the structure of the MMDB, IP ranges are converted to a binary representation, and they are used to return only the IP metadata information and not IP range information.
Special point: Is it always only IP metadata?
Outside the scope of the MMDB database, let’s talk about the capabilities of the mmdbctl tool. The mmdbctl tool can do extra things to return extra information in special circumstances.
mmdbctl can return input IP addresses
When you are outputting to TSV
or CSV
format data, the mmdbctl
tool will add an extra column natively called IP
, which represents the input IP address:
mmdbctl read 54.38.15.136 company_sample.mmdb -f csv
mmdbctl can support outputting IP range column
You can return the IP range or network information when querying the MMDB database. For that, you have to import/compile the MMDB database yourself from the CSV database.
IPinfo does not add the
network
column to their mmdb database by default. We use the--no-network
declaration when importing/compiling to MMDB databases.
Compile the CSV IP address database to an MMDB database using the following command.
mmdbctl import --in company_sample.csv --out company_sample_network.mmdb
Then query the MMDB database as usual:
mmdbctl read 54.38.15.136 company_sample_network.mmdb
Notice the network
column there. The network column just represents the range in the IP database. It does not indicate the parent range or prefix of the input IP address.
The
network
column has no impact or significance from a parent range perspective. Thenetwork
column does not indicate parent range or prefix declaration as derived from WHOIS and BGP records. The network column has no significance outside the IP database’s boundaries. Use the ASN API service to get an IP address’s parent range or prefix information.
Representing IP range values in CIDR format
We can even take this one step further. Converting the IP address range (start_ip
, end_ip
) to their CIDR equivalent.
If you precompile the CSV to have their start_ip
, and end_ip
be converted to their CIDR equivalent using the IPinfo CLI, then import/compile the CSV file to MMDB format using the CLI, you can get the network value in the MMDB file in their CIDR format:
ipinfo range2cidr company_sample.csv > company_sample_cidr.csv
mmdbctl import --in company_sample_cidr.csv --out company_sample_network.mmdb
mmdbctl read 54.38.15.136 company_sample_network.mmd
Feel free to reply to this post if you have any questions or feedback.