How to obtain IP geolocation using the CLI

Query IP geolocation using the CLI


IP geolocation is the process of mapping a user’s IP address to its physical location. Whenever a user visits a website, that website can read their IP address. By querying a geolocation database or API, the website can obtain the user’s country, region, city, latitude, longitude and so much more. Websites use geolocation to provide a multitude of functionalities to their users such as marketing, advertising, content customization and so on. has a variety of libraries that can easily be integrated into websites. But how about if I just want to query geolocation on a command line? Well, now you can use the CLI written in the Go programming language to query an IP address for its geolocation. With this CLI tool, you can easily check geolocation for IP addresses in log files and much more.

Below, we’ll show to install the CLI tool as well as the prerequisites. Then, we’ll show you some of the usage so that you can easily get started. Our demo machine is a Debian 12 instance so some of the steps will be for that platform.


  • You will need the API key. So, do sign up for the free plan at and take note of the API key given.
  • NOTE: You can still run the CLI without an API key but you’ll have less queries and less data.

How to Install

NOTE: We will list out the various ways you can install the CLI such as:

Option 1: Installing using .deb file for Debian/Ubuntu users

Check the latest release version at and update the commands below before running them.

curl -LO
sudo dpkg -i ip2location-io-1.1.0.deb

Option 2: Installing from Ubuntu PPA for Ubuntu users

Run the below commands.

sudo add-apt-repository ppa:ip2location/ip2locationio
sudo apt update
sudo apt install ip2location-io

Option 3: Installing via PowerShell for Windows users

Launch PowerShell as administrator. Then, run the command below.

iwr -useb | iex

Option 4: Downloading the pre-built binaries

If you just want the executable binaries, you can just download them at the page below and run them.

Option 5: Installing via Go

If you’re using Debian 12, then you can follow these steps to install Go, otherwise refer to for the Go installation steps.

sudo apt update
sudo apt install golang

Once you’ve installed Go, you can just run the below command to install the CLI.

go install

Run the below command to see which path is being used to store the CLI executable.

go env

Look for the GOPATH variable, which in our case is /home/admin/go so our installed executable is in /home/admin/go/bin folder.

Now you can just add /home/admin/go/bin into your PATH environment variable for your platform. In Debian, we’ll just add the path into the ~/.bash_profile by adding the below lines.

export PATH=$PATH:/home/admin/go/bin

After saving the file, you can need to run the below to reload the path.

source ~/.bash_profile

Now, you should be able to just call the CLI without a path so let’s try a simple command below to test.

ip2locationio -v

If your path has been set correctly, you’ll see the CLI’s version. Let’s explore some of the parameters we can use with CLI.

How to Use The CLI

We will cover topics on how to use the CLI as below:

Display the help

Command line users rely on the help display to show them what parameters are required by a particular command. The CLI can display the help in a similar fashion with the below command.

ip2locationio -h
Display help for CLI

Configure the API key

Before you can retrieve IP geolocation data, you will need to configure the CLI with the API key. Run the below command to configure your API key.

ip2locationio config <API KEY>

Check my own public IP geolocation

Let’s see what IP geolocation data is returned for my own public IP address. Run the command and see.

Your own public IP geolocation result

The above is my public IP geolocation using the Security plan which contains all the available fields. You may see less fields depending on your API plan.

If you wish to see a pretty print version, you can add 1 parameter like below.

ip2locationio -o pretty
Pretty print your own public IP geolocation result

Query any IP address for the geolocation

The CLI can accept either an IPv4 or an IPv6 address. Just try the below command.

IP geolocation result

Or do a pretty print with the below command.

ip2locationio -o pretty
Run pretty print command to view the IP result

Filter the result fields

Often times, we may just need a few fields from the result. You can easily filter the fields you wish to display like below. You can just give a comma separated list of the field names you wish to show. Nested fields can be called using periods.

ip2locationio -f country_code,region_name,city_name,,time_zone_info.olson
Filter the IP geolocation result by fields

Specifying the language for translations

If you’re subscribed to the Plus or Security plans, then you have access to the translation data. Let’s say you wish to see the Spanish translation. You can just call the command like below.

ip2locationio -l es -f country_name,country.translation.value,region_name,region.translation.value,city_name
Specify the IP geolocation data by using translations


It is that simple to use the CLI to get the IP geolocation for an IP address. Combine this with other commands and you can analyze data or build reports easily.

If you see the help display, you will notice that there are a few more commands at the bottom. We won’t cover those as they are not related to IP geolocation. But feel free to try them out as well.


Find a solution that help in your business.

Was this article helpful?

Related Articles