https://github.com/onel/freegeoip
Free geoip info for client requests
https://github.com/onel/freegeoip
Last synced: about 1 year ago
JSON representation
Free geoip info for client requests
- Host: GitHub
- URL: https://github.com/onel/freegeoip
- Owner: onel
- License: mit
- Created: 2024-01-05T17:08:13.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-14T11:20:14.000Z (about 2 years ago)
- Last Synced: 2024-04-15T10:33:45.743Z (about 2 years ago)
- Language: Python
- Size: 6.84 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```json
{
"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/](https://free-geoip.ey.r.appspot.com/)
## How to deploy
1. Pull repo
```sh
git clone https://github.com/onel/freegeoip .
cd freegeoip
```
2. Create a new project in [Google cloud console](https://console.cloud.google.com) and an [App engine app](https://console.cloud.google.com/appengine).
3. Setup local configurations for this new project
```sh
gcloud config configurations create [project_id]
gcloud config set project [project_id]
gcloud auth login
gcloud app deploy . --version 1
```
4. Make requests to that endpoint to get getip info
```javascript
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