I recently wrote microservice in Python with Flask that maps a user’s IP address to their location and provides country, locale, timezone and keyboard layout information.

I wrote it because I was using another service which did similar, but it stopped working when using it with my Void Linux installation scripts. I use this service to detect the user’s location from their IP, to set the locale, closest repository mirror, timezone and keyboard layout.

The service is designed to be used as a useful API in scripts or programs and supports providing information in tabular (HTML), plain text (line-by-line), JSON and XML formats.

For instance, the client can get their location information in tabular form by visiting https://ip-locator.xyz/table/client:

IP-Locator.xyz table client response

But we can also save it with curl:

curl -s https://ip-locator.xyz/table/client > response.html

Another typical use (and what I use with my void-setup script) is to receive the file in plain text:

curl -s https://ip-locator.xyz/text/client > response

Where the response file is something like:

GB
United Kingdom
https://flagsapi.com/GB/flat/64.png
London
Europe
cy_GB
en_GB
Europe/London
[public IP v4 address]]
qwerty-uk
qwerty-en

We could get the response in JSON format, as with the following sample Python program:

import json
import requests

def get_location():
    response = requests.get('https://ip-locator.xyz/json/client').json()
    print(json.dumps(response, ensure_ascii=False, indent=4))

if __name__ == '__main__':
    get_location()

This will print something like:

{
    "country": "GB",
    "country_name": "United Kingdom",
    "flag": "https://flagsapi.com/GB/flat/64.png",
    "city": "London",
    "region": "Europe",
    "locale": "cy_GB",
    "en_locale": "en_GB",
    "tz": "Europe/London",
    "ip": "[public IP v4 address]",
    "kb_layout": "qwerty-uk",
    "en_kb_layout": "qwerty-en"
}

We can also get the record as JSON from a given public IP v4 address such as 159.89.16.14:

https://ip-locator.xyz/json/159.89.16.14

For a full list of API paths, please refer to the usage page:

https://ip-locator.xyz

I hope that you find this service useful.