Enrich IP addresses with the CLI and get specific columns of data

Using IPinfo CLI’s bulk command and csvcut tool, you can enrich thousands of IP addresses in a few moments.

ezgif.com-optimize (4)

Intro to the CLI

First, get started by installing the IPinfo CLI.

The CLI comes with the bulk lookup command.

:link: IPinfo CLI - bulk command Documentation

Assuming your IP addresses are stored in the ips.txt file, all you have to do is pass that file to the ipinfo bulk command like so:

ipinfo bulk ips.txt 
If you don't have an ips.txt file handy, feel free to try out these IP addresses:

If you have a massive list of IP addresses, you can split them into manageable chunks with the command split. Here is a Stackoverflow thread discussing this: bash - How can I split a large text file into smaller files with an equal number of lines? - Stack Overflow

Saving the output file

You can save the enriched IP data to a CSV file like so:

ipinfo bulk -c ips.txt > ip_data.csv

The -c option is for CSV. You can also output the result in JSON with -j option.

Extracting specific columns

You can extract the specific columns from the enriched ip_data.csv file using csvkit utility, and it’s included csvcut tool. csvcut supports multiple column names in one command as well.

We are going to extract the following columns:

  • ip
  • city
  • region
  • country
  • country_name
csvcut -c ip,city,region,country,country_name ip_data.csv > ip_data_extracted.csv