# IP Geolocation

> A self-hosted IP geolocation and timezone API written in Rust. The GeoLite2 database ships inside the container, so lookups need no API key, no account and no third-party call.

- **Tagline:** An address becomes a place.
- **Source:** https://github.com/vpetersson/ipgeolocation
- **Language:** Rust
- **License:** MIT
- **Container image:** `ghcr.io/vpetersson/ipgeolocation`
- **Live demo:** https://geoip.vpetersson.com
- **At a glance:** 0 third-party calls; JSON and protobuf; GeoLite2 in the image; amd64 and arm64

A self-hosted IP geolocation and timezone API. The MaxMind GeoLite2 database and the timezone boundaries ship inside the container, so a lookup is a local read rather than a call to somebody else's service.

## The API

Two shapes. The short one keeps a small, stable payload. The `/v1` one adds currency,
calling code, flags and the rest.

```text
# The caller's own address, detected from proxy headers
GET /

# A specific address, short shape
GET /ipgeo?ip=8.8.8.8

# A specific address, full shape
GET /v1/ipgeo?ip=8.8.8.8

# Coordinates to timezone. Note the parameter is `long`, not `lon`.
GET /timezone?lat=51.5074&long=-0.1278
```

The service also publishes `/openapi.yaml` and `/llms.txt`, so it can describe itself to
a code generator and to an agent without anyone hand-writing a client.

## Run your own

The image carries its own data, so there is no API key to obtain and no account to
create.

```bash
docker run -p 3000:3000 ghcr.io/vpetersson/ipgeolocation:latest
curl "http://localhost:3000/ipgeo?ip=8.8.8.8"
```

Put it behind your proxy and it reads `CF-Connecting-IP`, `X-Real-IP` and
`X-Forwarded-For`, so `GET /` answers for the real caller rather than for the proxy. An
in-memory LRU sits in front of the database, and responses carry `Cache-Control` so a
proxy can hold them too.

---

Source: https://vpetersson.com/projects/ipgeolocation/
