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:

66.240.233.32
109.13.221.0
107.34.237.73
118.166.129.248
54.68.165.229
144.98.136.121
89.226.213.133
96.10.4.231
123.39.7.82
200.160.23.140
11.215.203.111
177.143.236.157
169.46.7.230
152.89.202.68
175.28.82.1
102.246.79.206

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

image