Ruby

Contributed by Robert Schäfer - https://github.com/roschaefer to the popular Geocoder - https://github.com/alexreisner/geocoder - gem.

Installation

gem install geocoder

Configuration

First create a Rails initializer with basic configuration

rails generate geocoder:config

Then update your config/initializers/geocoder.rb file to look like below;

# config/initializers/geocoder.rb
Geocoder.configure(
ip_lookup: :ipdata_co,
# to use an API key:
api_key: "test",
)

Usage

results = Geocoder.search("172.56.21.89")
results.first.coordinates
=> [30.267153, -97.7430608]
results.first.country_name
=> "United States"