Database Operations


Getting specific country location


You can filter out the IP addresses from any specific country by using the grep command from your terminal. One thing to remember is that you must start and end the country code with commas, for example: ,US,,IN,,CA, etc.


(head -1 location.csv;grep ",US," location.csv) > location_us.csv


If you use the solution above, your outputted CSV file will contain the header row as well.



Filtering the database with multiple countries/ASNs


Like filtering the database based on a single country or ASN, creating a sub-database containing multiple specific countries or ASNs is also possible. Let’s demonstrate that using multiple country filters. Get started by creating a text file(countries.txt) that contains your target countries in the following fashion:


,CA,
,FR,
,US,
,DE,
,UK,


As we will be using grep, your country code information must include the starting and trailing commas. Then using the -f option (stands for fixed-strings) run the following command.


(head -1 location.csv;grep -f countries.txt location.csv) > filtered_location.csv


This will create a filtered_locations.csv contains IP information of only the countries included in the countries.txt filter list.





Convert IP addresses to IP ranges


If you want to convert the IP address range columns (start_ipend_ip) to their CIDR equivalent, you can use our IPinfo CLI app. The range2cidr command of the IPinfo CLI will convert the two columns to their individual CIDR equivalent. For example:




How to use the range2cidr command:


  1. Install the IPinfo CLI from GitHub
  2. Unzip the downloaded IPinfo CSV database
  3. Run then range2cidr command of the IPinfo CLI and save the output to a file
  4. The outputted file would have the start_ip and end_ip columns converted to cidr column


ipinfo range2cidr location.csv > location_range.csv


Exploring MMDB files using mmdbctl


Our open source mmdbtctl makes exploration and management of MMDB files exceptionally easy.


Feel free to explore the documentation here: https://github.com/ipinfo/mmdbctl






Using MMDB reader libraries


If you want to read the MMDB database file using a programming language, you can use an MMDB reader library. The MMDB reader libraries supported by IPinfo are:



Using the MMDB reader library, you can open the database and lookup an IP address. Using the mmdbctl tool, you can create your own custom MMDB databases as well. If you need any assistance with using these libraries, feel free to reach out to us.


Rate limit for data downloads


We restrict the number of times a database can be downloaded to three times per day. This restriction applies to each unique IP address for an individual device. However, we are happy to accommodate requests to increase download limits. Learn more about rate limits on data downloads.


Checksums API endpoint

Checksums are essential for ensuring data integrity and security. By comparing the calculated hash values with the provided checksums, users can verify that their downloaded files haven't been tampered with or corrupted during transit.


We offer checksums API endpoints for every data download, supporting all the file formats. Checksums API response includes three hash values: md5, sha1, and sha256. Aside from the API endpoint, you can view checksums from your data downloads page on your account dashboard.


curl https://api.ip.cc/data/free/country.csv.gz/checksums?token=<YOUR_TOKEN>


{
  "checksums": {
    "md5": "75405cbe6ae89342dc4c58eede9f4bb2",
    "sha1": "8713da968c5bc0d89eba45ea349f75ac5569e21a",
    "sha256": "376f8148b250948bd236c00f4a00c95d2a22696ed3313141e9666af852f9bf1c"
  }
}