Using IP2Location.io Command Line Tool

The IP2Location.io command line interface (CLI) tool empowers users, network administrators, and developers to effortlessly retrieve IP geolocation information of an IP address. This includes details like country, region, city, domain, usage type, proxy, and more. The tool is incredibly lightweight and can be easily installed on your preferred operating system. All you need to do is register for a free “IP2Location.io IP Geolocation Free Plan” to start using it.

How to install IP2Location.io CLI

IP2Location.io supports various installation methods for different operating systems.
Below is the installation guide using the "Go Install" method.

go install github.com/ip2location/ip2location-io-cli/ip2locationio@latest

For alternative installation, please visit the IP2Location.io GitHub or click on the button below.

 Windows  Debian  Ubuntu  Git

How to configure the IP2Location.io API Key

You will need an API key to get started. If you don't have one, register for a free IP2Location.io API key and follow the instructions in the documentation page below to configure the API key.

ip2locationio config <API KEY>

Example of IP Geolocation Lookups

Query own public IP geolocation

You can easily find out your own public IP address and its geolocation information by entering the following command without any parameters.

ip2locationio

Output

{"ip":"3.87.189.160","country_code":"US","country_name":"United States of America","region_name":"Virginia","city_name":"Ashburn","latitude":39.039474,"longitude":-77.491809,"zip_code":"20146","time_zone":"-04:00","asn":"14618","as":"Amazon.com Inc.","isp":"Amazon Data Services NoVa","domain":"amazon.com","net_speed":"T1","idd_code":"1","area_code":"703","weather_station_code":"USVA0027","weather_station_name":"Ashburn","mcc":"-","mnc":"-","mobile_brand":"-","elevation":83,"usage_type":"DCH","address_type":"Unicast","continent":{"name":"North America","code":"NA","hemisphere":["north","west"],"translation":{"lang":null,"value":null}},"district":"Loudoun County","country":{"name":"United States of America","alpha3_code":"USA","numeric_code":840,"demonym":"Americans","flag":"https://cdn.ip2location.io/assets/img/flags/us.png","capital":"Washington, D.C.","total_area":9826675,"population":331002651,"currency":{"code":"USD","name":"United States Dollar","symbol":"$"},"language":{"code":"EN","name":"English"},"tld":"us","translation":{"lang":null,"value":null}},"region":{"name":"Virginia","code":"US-VA","translation":{"lang":null,"value":null}},"city":{"name":"Ashburn","translation":{"lang":null,"value":null}},"time_zone_info":{"olson":"America/New_York","current_time":"2023-11-03T03:50:17-04:00","gmt_offset":-14400,"is_dst":true,"sunrise":"07:39","sunset":"18:07"},"geotargeting":{"metro":"511"},"ads_category":"IAB19-11","ads_category_name":"Data Centers","is_proxy":false,"proxy":{"last_seen":2,"proxy_type":"DCH","threat":"-","provider":"-","is_vpn":false,"is_tor":false,"is_data_center":true,"is_public_proxy":false,"is_web_proxy":false,"is_web_crawler":false,"is_residential_proxy":false,"is_spammer":false,"is_scanner":false,"is_botnet":false}}

Query IP geolocation for specific IP

You can specify an IP address, either IPv4 or IPv6, to manually look up the geolocation information of that specific IP address. The result will be returned in JSON format.

ip2locationio 8.8.8.8

Output

{"ip":"8.8.8.8","country_code":"US","country_name":"United States of America","region_name":"California","city_name":"Mountain View","latitude":37.38605,"longitude":-122.08385,"zip_code":"94035","time_zone":"-07:00","asn":"15169","as":"Google LLC","isp":"Google LLC","domain":"google.com","net_speed":"T1","idd_code":"1","area_code":"650","weather_station_code":"USCA0746","weather_station_name":"Mountain View","mcc":"-","mnc":"-","mobile_brand":"-","elevation":32,"usage_type":"DCH","address_type":"Anycast","continent":{"name":"North America","code":"NA","hemisphere":["north","west"],"translation":{"lang":null,"value":null}},"district":"Santa Clara County","country":{"name":"United States of America","alpha3_code":"USA","numeric_code":840,"demonym":"Americans","flag":"https://cdn.ip2location.io/assets/img/flags/us.png","capital":"Washington, D.C.","total_area":9826675,"population":331002651,"currency":{"code":"USD","name":"United States Dollar","symbol":"$"},"language":{"code":"EN","name":"English"},"tld":"us","translation":{"lang":null,"value":null}},"region":{"name":"California","code":"US-CA","translation":{"lang":null,"value":null}},"city":{"name":"Mountain View","translation":{"lang":null,"value":null}},"time_zone_info":{"olson":"America/Los_Angeles","current_time":"2023-11-03T00:55:20-07:00","gmt_offset":-25200,"is_dst":true,"sunrise":"07:35","sunset":"18:08"},"geotargeting":{"metro":"807"},"ads_category":"IAB19-11","ads_category_name":"Data Centers","is_proxy":false,"proxy":{"last_seen":2,"proxy_type":"DCH","threat":"-","provider":"-","is_vpn":false,"is_tor":false,"is_data_center":true,"is_public_proxy":false,"is_web_proxy":false,"is_web_crawler":false,"is_residential_proxy":false,"is_spammer":false,"is_scanner":false,"is_botnet":false}}

Pretty print the result

To improve visibility, you can add the "-o pretty" option to display the result output in a more organized format instead of a single line.

ip2locationio -o pretty 8.8.8.8

Output

{
		"ip": "8.8.8.8",
		"country_code": "US",
		"country_name": "United States of America",
		"region_name": "California",
		"city_name": "Mountain View",
		"latitude": 37.38605,
		"longitude": -122.08385,
		"zip_code": "94035",
		"time_zone": "-07:00",
		"asn": "15169",
		"as": "Google LLC",
		"isp": "Google LLC",
		"domain": "google.com",
		"net_speed": "T1",
		"idd_code": "1",
		"area_code": "650",
		"weather_station_code": "USCA0746",
		"weather_station_name": "Mountain View",
		"mcc": "-",
		"mnc": "-",
		"mobile_brand": "-",
		"elevation": 32,
		"usage_type": "DCH",
		"address_type": "Anycast",
		"continent": {
				"name": "North America",
				"code": "NA",
				"hemisphere": [
						"north",
						"west"
				],
				"translation": {
						"lang": null,
						"value": null
				}
		},
		"district": "Santa Clara County",
		"country": {
				"name": "United States of America",
				"alpha3_code": "USA",
				"numeric_code": 840,
				"demonym": "Americans",
				"flag": "https://cdn.ip2location.io/assets/img/flags/us.png",
				"capital": "Washington, D.C.",
				"total_area": 9826675,
				"population": 331002651,
				"currency": {
						"code": "USD",
						"name": "United States Dollar",
						"symbol": "$"
				},
				"language": {
						"code": "EN",
						"name": "English"
				},
				"tld": "us",
				"translation": {
						"lang": null,
						"value": null
				}
		},
		"region": {
				"name": "California",
				"code": "US-CA",
				"translation": {
						"lang": null,
						"value": null
				}
		},
		"city": {
				"name": "Mountain View",
				"translation": {
						"lang": null,
						"value": null
				}
		},
		"time_zone_info": {
				"olson": "America/Los_Angeles",
				"current_time": "2023-11-03T00:56:00-07:00",
				"gmt_offset": -25200,
				"is_dst": true,
				"sunrise": "07:35",
				"sunset": "18:08"
		},
		"geotargeting": {
				"metro": "807"
		},
		"ads_category": "IAB19-11",
		"ads_category_name": "Data Centers",
		"is_proxy": false,
		"proxy": {
				"last_seen": 2,
				"proxy_type": "DCH",
				"threat": "-",
				"provider": "-",
				"is_vpn": false,
				"is_tor": false,
				"is_data_center": true,
				"is_public_proxy": false,
				"is_web_proxy": false,
				"is_web_crawler": false,
				"is_residential_proxy": false,
				"is_spammer": false,
				"is_scanner": false,
				"is_botnet": false
		}
}

Query IP geolocation for specific IP and show only specific fields

Instead of displaying the complete set of information, you have the option to customize the display and output specific fields. For example, the code below will display the country code, region name, city name, continent, and 3-character country code.

ip2locationio -f country_code,region_name,city_name,continent.name,country.alpha3_code 8.8.8.8

Output

country_code,region_name,city_name,continent.name,country.alpha3_code
"US","California","Mountain View","North America","USA"

The above examples demonstrate several usage scenarios. To learn more about the supported parameters, you can invoke "ip2locationio -h".

Additional Resources

IP2Location.io Github Project

Please visit the IP2Location.io Github project for the latest release and the complete guidelines.

Domain WHOIS Lookup CLI

Looking for Domain WHOIS Lookup Command Line Tool?
It helps users to access WHOIS domain information for a specific domain name.

Discover the World with IP Geolocation

Supercharge your business with Geolocation data.

Sign Up Free Account Access to 7 Days Trial