lguzzon-scratchbook / freegeoip

Free geoip info for client requests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FREE GEOIP SERVICE

Get free geoip data for requests for client requests.

This works thanks to some special headers added by Google App engine to each request that it serves.

For this reason, this can only be deployed on App engine.

App engine only returns some basic info like: latitude, longitude, city, country but if this is enough then you can get all this for free.

About

This is a simple Flask app that reads the special headers that Google App engine adds to each request and returns them as JSON.

Note: This only works for requests that come directly from the client's device (no way to request for a specific IP).

App engine has a decent free tier so this service can be run for free.

Example response:

{
	"city":"bucharest",
    "countryCode":"RO",
    "ipAddress":"xx.xxx.xxx.xx",
    "latitude":"44.426767",
    "longitude":"26.102538",
    "regionCode":"b"
}

Demo

Try it for free at https://free-geoip.ey.r.appspot.com/

How to deploy

  1. Pull repo
git clone https://github.com/onel/freegeoip .
cd freegeoip
  1. Create a new project in Google cloud console and an App engine app.

  2. Setup local configurations for this new project

gcloud config configurations create [project_id]
gcloud config set project [project_id]
gcloud auth login
gcloud app deploy . --version 1
  1. Make requests to that endpoint to get getip info
const url = '[your freegeoip endpoint]'
fetch(url)
    .then(response => response.json())
    .then(data => {
        console.log('JSON data:', data);
    })
    .catch(error => {
        console.error('Fetch error:', error);
    })

Stack

Python 3.9

Flask

Licence

MIT

About

Free geoip info for client requests

License:MIT License


Languages

Language:Python 100.0%