Giter Site home page Giter Site logo

freegeoip's Introduction

freegeoip ipstack

freegeoip - Important Announcement

[The old freegeoip API is now deprecated and will be discontinued on July 1st, 2018]

Launched more than 6 years ago, the freegeoip.net API has grown into one of the biggest and most widely used APIs for IP to location services worldwide. The API is used by thousands of developers, SMBs and large corporations around the globe and is currently handling more than 2 billion requests per day. After years of operation and the API remaining almost unchanged, today we announce the complete re-launch of freegeoip into a faster, more advanced and more scalable API service called ipstack (https://ipstack.com). All users that wish to continue using our IP to location service will be required to sign up to obtain a free API access key and perform a few simple changes to their integration. While the new API offers the ability to return data in the same structure as the old freegeoip API, the new API structure offers various options of delivering much more advanced data for IP Addresses.

Required Changes to Legacy Integrations (freegeoip.net/json/xml)

As of March 31 2018 the old freegeoip API is deprecated and a completely re-designed API is now accessible at http://api.ipstack.com. While the new API offers the same capabilities as the old one and also has the option of returning data in the legacy format, the API URL has now changed and all users are required to sign up for a free API Access Key to use the service.

  1. Get a free ipstack Account and Access Key

Head over to https://ipstack.com and follow the instructions to create your account and obtain your access token. If you only need basic IP to Geolocation data and do not require more than 10,000 requests per month, you can use the free account. If you'd like more advanced features or more requests than included in the free account you will need to choose one of the paid options. You can find an overview of all available plans at https://ipstack.com/product

  1. Integrate the new API URL

The new API comes with a completely new endpoint (api.ipstack.com) and requires you to append your API Access Key to the URL as a GET parameter. For complete integration instructions, please head over to the API Documentation at https://ipstack.com/documentation. While the new API offers a completely reworked response structure with many additional data points, we also offer the option to receive results in the old freegeoip.net format in JSON or XML.

To receive your API results in the old freegeoip format, please simply append &legacy=1 to the new API URL.

JSON Example: http://api.ipstack.com/186.116.207.169?access_key=YOUR_ACCESS_KEY&output=json&legacy=1

XML Example: http://api.ipstack.com/186.116.207.169?access_key=YOUR_ACCESS_KEY&output=xml&legacy=1

New features with ipstack

While the new ipstack service now runs on a commercial/freemium model, we have worked hard at building a faster, more scalable, and more advanced IP to location API product. You can read more about all the new features by navigating to https://ipstack.com, but here's a list of the most important changes and additions:

  • We're still free for basic usage

While we now offer paid / premium options for our more advanced users, our core product and IP to Country/Region/City product is still completely free of charge for up to 10,000 requests per month. If you need more advanced data or more requests, you can choose one of the paid plans listed at https://ipstack.com/product

  • Batch Requests

Need to validate more than 1 IP Address in a single API Call? Our new Bulk Lookup Feature (available on our paid plans) allows you to geolocate up to 50 IP Addresses in a single API Call.

  • Much more Data

While the old freegeoip API was limited to provide only the most basic IP to location data, our new API provides more than 20 additional data points including Language, Time Zone, Current Time, Currencies, Connection & ASN Information, and much more. To learn more about all the data points available, please head over to the ipstack website.

  • Security & Fraud Prevention Tools

Do you want to prevent fraudulent traffic from arriving at your website or from abusing your service? Easily spot malicious / proxy / VPN traffic by using our new Security Module, which outputs a lot of valuable security information about an IP Address.

Next Steps

  • Deprecation of the old API

While we want to keep the disruption to our current users as minimal as possible, we are planning to shut the old API down on July 1st, 2018. This should give all users enough time to adapt to changes, and should we still see high volumes of traffic going to the old API by that date, we may decide to extend it further. In any case, we highly recommend you switch to the new API as soon as possible. We will keep you posted here about any changes to the planned shutdown date.

  • Any Questions? Please get in touch!

It's very important to ensure a smooth transition to ipstack for all freegeoip API users. If you are a developer that has published a plugin/addon that includes the legacy API, we recommend you get in touch with us and also share this announcement with your users. If you have any questions about the transition or the new API, please get in touch with us at [email protected]

freegeoip - Deprecated Documentation

Deploy

This is the source code of the freegeoip software. It contains both the web server that empowers freegeoip.net, and a package for the Go programming language that enables any web server to support IP geolocation with a simple and clean API.

See http://en.wikipedia.org/wiki/Geolocation for details about geolocation.

Developers looking for the Go API can skip to the Package freegeoip section below.

Running

This section is for people who desire to run the freegeoip web server on their own infrastructure. The easiest and most generic way of doing this is by using Docker. All examples below use Docker.

Docker

Install Docker

Docker has install instructions for many platforms, including

Run the API in a container

docker run --restart=always -p 8080:8080 -d apilayer/freegeoip

Test

curl localhost:8080/json/1.2.3.4
# => {"ip":"1.2.3.4","country_code":"US","country_name":"United States", # ...

Other Linux, OS X, FreeBSD, and Windows

There are pre-compiled binaries available.

Production configuration

For production workloads you may want to use different configuration for the freegeoip web server, for example:

  • Enabling the "internal server" for collecting metrics and profiling/tracing the freegeoip web server on demand
  • Monitoring the internal server using Prometheus, or exporting your metrics to New Relic
  • Serving the freegeoip API over HTTPS (TLS) using your own certificates, or provisioned automatically using LetsEncrypt.org
  • Configuring HSTS to restrict your browser clients to always use HTTPS
  • Configuring the read and write timeouts to avoid stale clients consuming server resources
  • Configuring the freegeoip web server to read the client IP (for logs, etc) from the X-Forwarded-For header when running behind a reverse proxy
  • Configuring CORS to restrict access to your API to specific domains
  • Configuring a specific endpoint path prefix other than the default "/" (thus /json, /xml, /csv) to serve the API alongside other APIs on the same host
  • Optimizing your round trips by enabling TCP Fast Open on your OS and the freegeoip web server
  • Setting up usage limits (quotas) for your clients (per client IP) based on requests per time interval; we support various backends such as in-memory map (for single instance), or redis or memcache for distributed deployments
  • Serve the default GeoLite2 City free database that is downloaded and updated automatically in background on a configurable schedule, or
  • Serve the commercial GeoIP2 City database from MaxMind, either as a local file that you provide and update periodically (so the server can reload it), or configured to be downloaded periodically using your API key

See the Server Options section below for more information on configuring the server.

For automation, check out the freegeoip chef cookbook or the (legacy) Ansible Playbook for Ubuntu 14.04 LTS.

To see all the available options, use the -help option:

docker run --rm -it apilayer/freegeoip -help

If you're using LetsEncrypt.org to provision your TLS certificates, you have to listen for HTTPS on port 443. Following is an example of the server listening on 3 different ports: metrics + pprof (8888), http (80), and https (443):

docker run -p 8888:8888 -p 80:8080 -p 443:8443 -d apilayer/freegeoip \
	-internal-server=:8888 \
	-http=:8080 \
	-https=:8443 \
	-hsts=max-age=31536000 \
	-letsencrypt \
	-letsencrypt-hosts=myfancydomain.io

You can configure the freegeiop web server via command line flags or environment variables. The names of environment variables are the same for command line flags, but prefixed with FREEGEOIP, all upperscase, separated by underscores. If you want to use environment variables instead:

$ cat prod.env
FREEGEOIP_INTERNAL_SERVER=:8888
FREEGEOIP_HTTP=:8080
FREEGEOIP_HTTPS=:8443
FREEGEOIP_HSTS=max-age=31536000
FREEGEOIP_LETSENCRYPT=true
FREEGEOIP_LETSENCRYPT_HOSTS=myfancydomain.io

$ docker run --env-file=prod.env -p 8888:8888 -p 80:8080 -p 443:8443 -d apilayer/freegeoip

By default, HTTP/2 is enabled over HTTPS. You can disable by passing the -http2=false flag.

Also, the Docker image of freegeoip does not provide the web page from freegeiop.net, it only provides the API. If you want to serve that page, you can pass the -public=/var/www parameter in the command line. You can also tell Docker to mount that directory as a volume on the host machine and have it serve your own page, using Docker's -v parameter.

If the freegeoip web server is running behind a reverse proxy or load balancer, you have to run it passing the -use-x-forwarded-for parameter and provide the X-Forwarded-For HTTP header in all requests. This is for the freegeoip web server be able to log the client IP, and to perform geolocation lookups when an IP is not provided to the API, e.g. /json/ (uses client IP) vs /json/1.2.3.4.

Database

The current implementation uses the free GeoLite2 City database from MaxMind.

In the past we had databases from other providers, and at some point even our own database comprised of data from different sources. This means it might change in the future.

If you have purchased the commercial database from MaxMind, you can point the freegeoip web server or (Go API, for dev) to the URL containing the file, or local file, and the server will use it.

In case of files on disk, you can replace the file with a newer version and the freegeoip web server will reload it automatically in background. If instead of a file you use a URL (the default), we periodically check the URL in background to see if there's a new database version available, then download the reload it automatically.

All responses from the freegeiop API contain the date that the database was downloaded in the X-Database-Date HTTP header.

API

The freegeoip API is served by endpoints that encode the response in different formats.

Example:

curl freegeoip.net/json/

Returns the geolocation information of your own IP address, the source IP address of the connection.

You can pass a different IP or hostname. For example, to lookup the geolocation of github.com the server resolves the name first, then uses the first IP address available, which might be IPv4 or IPv6:

curl freegeoip.net/json/github.com

Same semantics are available for the /xml/{ip} and /csv/{ip} endpoints.

JSON responses can be encoded as JSONP, by adding the callback parameter:

curl freegeoip.net/json/?callback=foobar

The callback parameter is ignored on all other endpoints.

Metrics and profiling

The freegeoip web server can provide metrics about its usage, and also supports runtime profiling and tracing.

Both are disabled by default, but can be enabled by passing the -internal-server parameter in the command line. Metrics are generated for Prometheus and can be queried at /metrics even with curl.

HTTP pprof is available at /debug/pprof and the examples from the pprof package documentation should work on the freegeiop web server.

The freegeoip package for the Go programming language provides two APIs:

  • A database API that requires zero maintenance of the IP database;
  • A geolocation http.Handler that can be used/served by any http server.

tl;dr if all you want is code then see the example_test.go file.

Otherwise check out the godoc reference.

GoDoc Build Status GoReportCard

Features

  • Zero maintenance

The DB object alone can download an IP database file from the internet and service lookups to your program right away. It will auto-update the file in background and always magically work.

  • DevOps friendly

If you do care about the database and have the commercial version of the MaxMind database, you can update the database file with your program running and the DB object will load it in background. You can focus on your stuff.

  • Extensible

Besides the database part, the package provides an http.Handler object that you can add to your HTTP server to service IP geolocation lookups with the same simplistic API of freegeoip.net. There's also an interface for crafting your own HTTP responses encoded in any format.

Install

Download the package:

go get -d github.com/apilayer/freegeoip/...

Install the web server:

go install github.com/apilayer/freegeoip/cmd/freegeoip

Test coverage is quite good, and test code may help you find the stuff you need.

freegeoip's People

Contributors

dam660 avatar emilburzo avatar fiorix avatar gleicon avatar gui avatar if-kenn avatar infertux avatar julian-zehetmayr avatar lpereira avatar lxfontes avatar mathieu-aubin avatar matthiasn avatar messerf avatar mourner avatar omercnet avatar own3mall avatar pierreozoux avatar samnissen avatar wbyoung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

freegeoip's Issues

DELETE/ANONYMIZE endpoint for looked up IPs

Do you have (or plan to have) any kind of endpoint that someone could triggered to delete/anonymize a looked up IP? Within the GDPR process we need to make sure that all the data that we deliver to as they call "third-party processor" need also to be GDPR compliant.

website's signup page's SSL is broken

Guys, i was supposed to login and use your service but in my surprise the site's signup page's SSL is broken. I'm little disappointed and concern to see this, but i understand sometimes things happens but this is serious bug, please do fix this, i need to signup

Flag of India served by IPstack is wrong.

Currently, ipstack.com serves Indian Flag at http://assets.ipstack.com/flags/in.svg, which is wrong. The Ashoka Chakra should not leave the white stripe.

You can read the flag code of India here: https://knowindia.gov.in/assets/doc/flagcodeofindia_eng.pdf

You can read more about the Ashok Charka itself on Wikipedia at https://en.wikipedia.org/wiki/Ashoka_Chakra
and about the Flag at https://en.wikipedia.org/wiki/Flag_of_India

Also, the Flag at Wikimedia Commons(https://commons.wikimedia.org/wiki/File:Flag_of_India.svg) is available in the public domain.

Edit: https://restcountries.eu/data/ind.svg is correct.

List of all continents, countries and regions in the world

Is there a master data of all the continents, countries and regions that ipstack.com returns with?

I tried searching the internet, but was unable to find them. I would like to use ipstack.com, so I will require the codes that match with what is returned by ipstack.com

Resulting Docker image size ~800MB? Alpine?

Hello guys, that's a great idea for such service and thank you very much.
But resulting docker image is > 800MB, just for an API that provides access to GeoLite2-City.mmdb.gz (±30mb) the additionnal 770MB sounds like too much.

You are using debian golang 1.9 image (>200mb) maybe switch to Alpine?
This is only issue sofar.

Deprecation Message using output=json&legacy=1?

I run the local windows build of freegeoip inside some powershell scripts.

I start the server with:
freegeoip.exe -ArgumentList "-http=:1234 -silent -tcp-fast-open"

I geoip using:
PS C:\Users> Invoke-WebRequest -Uri "http://localhost:1234/json/186.116.207.169?access_key=SOMEKEY&output=json&legacy=1" -UseBasicParsing | Select -Expand Content | ConvertFrom-Json

This returns:

__deprecation_message__ : This API endpoint is deprecated and will stop working on July 1st, 2018. For more information please visit: https://github.com/apilayer/freegeoip#readme
ip                      : 186.116.207.169
country_code            : CO
country_name            : Colombia
region_code             :
region_name             :
city                    :
zip_code                :
time_zone               : America/Bogota
latitude                : 4.5981
longitude               : -74.0758
metro_code              : 0

I am concerned why the deprecation_message message shows up? The local method I am using, will this stop working in the near future? If so, how should I be calling the Invoke-WebRequest to prevent this from happening?

The local version I am using is 3.5.0.

"Incorrect" data keys in legacy mode

Recently switched over from freegeoip.net/xml/, appending the &legacy=1 param to the request. However the shape of the data returned isn't identical to the old data. For example, countryCode is now country_code.

Not sure if this something you would want to address at your API level (as I get the feeling freegeoip is the face of multiple APIs that have been deprecated), but I thought I'd create an issue anyway for anyone facing the same issue.

ssl encryption

While I appreciate the free tier and your freemium business model, withholding SSL for the free tier seems unnecessarily insecure. The rest of the features are more than enough incentive to upgrade plans without compromising peoples security.

Adblock issues

uBlock Origin seems to be blocking requests to the ipstack.com API made on client-side, do you have any solution for that?

Raise http exception when the response is error message

It is quite difficult to handle exception case when it is occured. Naturally it is expected to have http status error from response but http status code is always OK(200) despite it returns error result.

I can easily detect error by checking http status code and deserialize json result according to status code. Otherwise it is very ugly to handle success and error response in the code.

Incorrect certificate on freegeoip.io

freegeoip.io uses an invalid security certificate. The certificate is only valid for the following names: plex.freegeoip.io, plextools.freegeoip.io

'geoip' failed to build: COPY failed

Hi,
I am trying to build freegeoip image from a docker-compose file but without success so far.
I am getting below issue indeed:

[root@vps....]# docker-compose up -d
Building geoip
Step 1/8 : FROM golang:1.9
 ---> ef89ef5c42a9
Step 2/8 : COPY cmd/freegeoip/public /var/www
ERROR: Service 'geoip' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder927407744/cmd/freegeoip/public: no such file or directory

This is what I have in my v3 docker-compose file:
Dockerfile of freegeoip being in /freegeoip folder

geoip:
   build: freegeoip
   network_mode: "host"
   environment:
   - FREEGEOIP_INTERNAL_SERVER=:8888
   - FREEGEOIP_HTTP=:9090
   logging:
     driver: "json-file"
     options:
       max-size: "5m"
       max-file: "2"

Am I doing something wrong?

Thank you
Fabrice

use custom cert/key

docker run -p 8888:8888 -p 8001:8080 -p 8000:8443 -d apilayer/freegeoip -internal-server=:8888 -http=:8080 -https=:8443 -hsts=max-age=31536000 -cert=/home///filename_full.crt -key=/home///key.key

2018/05/14 05:07:41 freegeoip internal server starting on :8888
2018/05/14 05:07:41 database info: starting update
2018/05/14 05:07:41 freegeoip http server starting on :8080
2018/05/14 05:07:41 freegeoip https server starting on :8443
2018/05/14 05:07:41 listener: cert/key failed: open /home///filename_full.crt: no such file or directory

How do I pass the cert/key to the docker container, do I need to mount the /home/**/** to the container.

AND

How to configure nginx to run a proxy_pass to the container?

The repo is great, too bad its going to be deprecated soon.
Hoping for a quick response.

Thanks

Accessing GeoLite2 database in 2020

For those of us who are building this or using a Docker image, is there a way to configure things properly now that public access to downloading the MaxMind databases is no longer possible? Without changes, it seems as though the URL being accessed is for a domain that's no longer resolvable. And even if the URL was updated, I'd expect permission errors without incorporating the newly required license keys.

I tried using the username/license key setup, but that didn't end up working. The downloaded file was tiny and just said that the account ID was missing.

My current (workaround) plan is to incorporate the geoipupdate into a custom docket image that extends the image I'm currently using (I'm still on a slightly older version right now). Then have that run periodically through some other script (maybe an ENTRYPOINT script as cron feels heavyweight). Finally, I'll change the freegeoip config to use this file.

This seems like it would work for me, but I'd hate to do this work and find out I'm just missing something here. Also, I wouldn't want others to also have to go through this when they're just looking for the same functionality. Hopefully we can get something done here instead!

Self hosted future?

We've been running a self-hosted version of freegeoip for years (ever since the public service started having uptime issues). What's happening to that? Everything I'm reading on here revolves around the public API/service being replaced with a freemium model. =/

Quota increase using docker?

I'm running freegeoip in an AWS EC2 t2.micro instance using docker. The application runs fine on port 8080 with this command:
sudo docker run --restart=always -p 8080:8080 -d f iorix/freegeoip -public=/var/www
But I believe this has the default limit of 10000 requests per hour. When I try
sudo docker run --restart=always -p 8080:8080 -d f iorix/freegeoip -public=/var/www -quota-max 50000
and open the webpage, I get the error: "Service unavailable, try again later"
Am I passing the -quota-max option wrong here?

Troubleshooting Let's Encrypt Certificate Failures

How do we figure out why Let's Encrypt is failing?

Is the reason why Let's Encrypt integration failed logged anywhere? I can't seem to figure out why my certificate won't pull / renew anymore.

I run this command:

docker run --restart=always -p 33333:33333 -p 443:443 -v /var/www/geoservices:/tmp/www -i -t fiorix/freegeoip -http :33333 -https :443 -public /tmp/www -letsencrypt -letsencrypt-email [email protected] -letsencrypt-hosts www.{MYDOMAIN},{MYDOMAIN}

and get this output when using https://

[error] 2018/03/01 17:31:33 http: TLS handshake error from {MYIP}: acme/autocert: missing certificate
[error] 2018/03/01 17:31:34 http: TLS handshake error from {MYIP}: acme/autocert: missing certificate

I had it working at one point, but now it appears to be failing, and I don't know how to troubleshoot the error code received from Let's Encrypt. Can anyone help?

apilayer/freegeoip docker image doesn't exist

I know that this repo just barely changed hands but I just wanted to create an issue to track this problem:

λ ~/code/freegeoip/ master docker run --restart=always -p 8080:4444 -d apilayer/freegeoip
Unable to find image 'apilayer/freegeoip:latest' locally
docker: Error response from daemon: pull access denied for apilayer/freegeoip, repository does not exist or may require 'docker login'.
See 'docker run --help'.

Google Chrome is blocking site because of cert issue

I think you just need to update the certificate on your site

Google chrome is blocking site with following message:

freegeoip.io normally uses encryption to protect your information. When Google Chrome tried to connect to freegeoip.io this time, the website sent back unusual and incorrect credentials. This may happen when an attacker is trying to pretend to be freegeoip.io, or a Wi-Fi sign-in screen has interrupted the connection. Your information is still secure because Google Chrome stopped the connection before any data was exchanged.

You cannot visit freegeoip.io right now because the website uses HSTS. Network errors and attacks are usually temporary, so this page will probably work later.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.