IPReveal
Shows your IPv4 and IPv6 address, location and network, in the browser or with curl.
What it is
- Shows your public IPv4 and IPv6 address, your approximate location and your network provider (ASN).
- Works in the browser, or from a terminal: curl ipreveal.me prints just your IP.
- A plain-text and JSON API for your own address or any address you look up.
- No cookies, no analytics and no third-party scripts.
The problem
A “what’s my IP” service sounds trivial, but it is easy to get wrong. Behind proxies, the address a server sees is often the proxy’s, and the headers that carry the real one can be forged by anyone. Inside Docker, IPv6 visitors can lose their real address before the app ever sees it.
It also handles the one piece of personal data people visit it for, so I wanted it to be private by default rather than by policy.
How I built it
- Wrote the API in Go with Fiber: plain-text and JSON endpoints for IP, location, user agent, ASN and lookups of any address. It keeps no state beyond Redis.
- Only trusted known proxies to report a visitor’s address, so forwarding headers from anyone else are ignored and cannot spoof the result.
- Cut every IP down to its /24 (IPv4) or /48 (IPv6) network before it is written to the logs, which rotate as JSON files.
- Rate limited each client with a true sliding window in a Redis sorted set: trim, add, count and read the oldest entry in one MULTI/EXEC. A rejected request is taken back out of the window, so a client that keeps hammering is not locked out forever, and browser preflights are answered before the limiter so they are never counted.
- Put Varnish in front: it routes /api to Go and everything else to the static site, caches lookups of other addresses for an hour, and never caches “my IP” answers. Cached lookups are stored without their rate-limit headers, so one caller’s quota is never replayed to the next.
- Taught Varnish to recognise curl, Wget, HTTPie, xh and PowerShell on the home page and answer them with plain text instead of HTML. Vary: User-Agent is added only on the way out, so downstream caches keep the two apart without splitting Varnish’s own cache.
- Rejected lookups of private, loopback, link-local, multicast and carrier-grade NAT addresses up front, since no database can say anything useful about them.
The interesting parts
Finding the real client address
The middleware first checks whether the TCP peer is one of the configured trusted proxies. If it is not, every forwarding header is ignored and the peer address is the answer. If it is, the code reads Cloudflare’s client-IP headers, and otherwise walks X-Forwarded-For from right to left, skipping trusted proxies and returning the first address that is not one. Walking from the right matters because the left end of that header is whatever the client chose to send.
A separate probe for real IPv6
The Docker host has no IPv6 networking, so behind docker-proxy every IPv6 visitor shows up as an internal 172.x address. I run a small nginx container with host networking on v6.ipreveal.me, port 8443, and binds the host’s public IPv6 address directly, so it sees the real visitor while still being containerised. It serves only the two “my IP” endpoints, with strict CORS so the main site can call it. A watcher checks the TLS certificate’s hash every hour and reloads nginx when it changes, so renewed certificates are picked up without downtime.
GeoIP updates without restarts
A geoipupdate sidecar downloads fresh MaxMind GeoLite2 City, Country and ASN databases every 24 hours. The Go service checks each file’s modification time and size every hour. When they change it opens the new files first, swaps the readers under a write lock and only then closes the old ones; lookups hold the read lock, so none is cut off mid-query. If the new City file is missing or will not open, it keeps serving the old data and tries again on the next change.
A strict CSP on a static Next.js site
A Next.js static export contains inline scripts, which normally pushes you towards an unsafe-inline content security policy. After the build, a script walks every generated HTML file, takes a SHA-256 hash of each executable inline script and writes them into a config file that nginx injects into the Content-Security-Policy header. The theme script that prevents a light/dark flash is moved into its own content-hashed file, served as immutable from the head, so the policy can stay at script-src self plus exact hashes.
How it runs
- One Docker Compose stack: the Go backend, the static frontend on nginx, Varnish, Redis, the GeoIP updater and the IPv6 probe. Cloudflare terminates visitor TLS, and Nginx Proxy Manager forwards to Varnish.
- Dedicated v4.ipreveal.me and v6.ipreveal.me endpoints let the page detect both addresses at once. An answer of the wrong family is discarded, so a misrouted host cannot show the wrong address.
- GitLab CI builds versioned backend and frontend images and triggers the infrastructure pipeline: the next branch deploys to dev automatically, and main deploys to production only after a manual approval.
- Each deploy keeps the previous release next to the new one and runs health checks. A missing image tag fails the deploy instead of falling back to latest, and rolling back production asks for a typed confirmation.
- The API’s logs are rotating JSON files kept for 60 days, with addresses already truncated to network prefixes.