Created
December 13, 2019 21:24
-
-
Save dpaluy/fe26fc53e0a95c3283587b35101a4e36 to your computer and use it in GitHub Desktop.
Free IP Geolocation API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Visit https://freegeoip.app/json/