Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Created December 13, 2019 21:24
Show Gist options
  • Select an option

  • Save dpaluy/fe26fc53e0a95c3283587b35101a4e36 to your computer and use it in GitHub Desktop.

Select an option

Save dpaluy/fe26fc53e0a95c3283587b35101a4e36 to your computer and use it in GitHub Desktop.
Free IP Geolocation API
# read more: https://freegeoip.app/
require 'uri'
require 'net/http'
require 'openssl'
# https://freegeoip.app/{format}/{IP_or_hostname}
url = URI("https://freegeoip.app/json/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/json'
response = http.request(request)
puts response.read_body
@dpaluy
Copy link
Author

dpaluy commented Dec 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment