Go to file
Daniel Carrillo 9070e9a2c2
Use Accept request header instead of user agent to figure out non-browser clients. Funny fact, I borrowed the idea from a fork ('8a3e142cf3/router/generic.go (L33)')
2022-04-30 17:35:12 +02:00
.github/workflows Remove timestamp snapshot from log when releasing 2022-03-19 19:08:02 +01:00
cmd Add optional secure headers to responses 2022-04-02 18:12:31 +02:00
integration-tests Use Accept request header instead of user agent to figure out non-browser clients. Funny fact, I borrowed the idea from a fork ('8a3e142cf3/router/generic.go (L33)') 2022-04-30 17:35:12 +02:00
internal Add optional secure headers to responses 2022-04-02 18:12:31 +02:00
models Tidy up the house 2022-01-27 13:17:51 +01:00
router Use Accept request header instead of user agent to figure out non-browser clients. Funny fact, I borrowed the idea from a fork ('8a3e142cf3/router/generic.go (L33)') 2022-04-30 17:35:12 +02:00
service Add CI and go-report badges. Add comments to make golint happy 2021-11-30 17:49:02 +01:00
test first commit 2021-11-10 20:06:12 +01:00
Dockerfile Update modules and bump go version to 1.18 2022-03-19 18:59:15 +01:00
LICENSE Fix LICENSE file, a tgz instead of text plain was commited by mistake 2021-11-18 13:04:38 +01:00
Makefile Update golangci-lint and shadow 2022-03-19 19:02:41 +01:00
README.md Use Accept request header instead of user agent to figure out non-browser clients. Funny fact, I borrowed the idea from a fork ('8a3e142cf3/router/generic.go (L33)') 2022-04-30 17:35:12 +02:00
go.mod Bump maxminddb-golang to 1.9.0 2022-04-02 18:07:12 +02:00
go.sum Bump maxminddb-golang to 1.9.0 2022-04-02 18:07:12 +02:00

README.md

What is my IP address

CI Go Report Card GitHub release License Apache 2.0

Just another "what is my IP address" service, including geolocation and headers information, written in go with high performance in mind, it uses gin which uses httprouter a lightweight high performance HTTP multiplexer.

Take a look at ifconfig.es a live site using whatismyip

Get your public IP easily from the command line:

curl ifconfig.es
127.0.0.1

curl -6 ifconfig.es
::1

Features

  • TLS and HTTP/2.
  • Can run behind a proxy by trusting a custom header (usually X-Real-IP) to figure out the source IP address.
  • IPv4 and IPv6.
  • Geolocation info including ASN. This feature is possible thanks to maxmind GeoLite2 databases. In order to use these databases, a license key is needed. Please visit Maxmind site for further instructions and get a free license.
  • High performance.
  • Self-contained server what can reload GeoLite2 databases and/or SSL certificates without stop/start. The hup signal is honored.
  • HTML templates for the landing page.
  • Text plain and JSON output.

Endpoints

Build

Golang >= 1.17 is required. Previous versions may work.

make build

Usage

Usage of ./whatismyip:
  -bind string
        Listening address (see https://pkg.go.dev/net?#Listen) (default ":8080")
  -geoip2-asn string
        Path to GeoIP2 ASN database
  -geoip2-city string
        Path to GeoIP2 city database
  -template string
        Path to template file
  -tls-bind string
        Listening address for TLS (see https://pkg.go.dev/net?#Listen)
  -tls-crt string
        When using TLS, path to certificate file
  -tls-key string
        When using TLS, path to private key file
  -trusted-header string
        Trusted request header for remote IP (e.g. X-Real-IP)
  -version
        Output version information and exit

Examples

Run a default TCP server

./whatismyip -geoip2-city ./test/GeoIP2-City-Test.mmdb -geoip2-asn ./test/GeoLite2-ASN-Test.mmdb

Run a TLS (HTTP/2) server only

./whatismyip -geoip2-city ./test/GeoIP2-City-Test.mmdb -geoip2-asn ./test/GeoLite2-ASN-Test.mmdb \
             -bind "" -tls-bind :8081 -tls-crt ./test/server.pem -tls-key ./test/server.key

Run a default TCP server with a custom template and trust a custom header set by an upstream proxy

./whatismyip -geoip2-city ./test/GeoIP2-City-Test.mmdb -geoip2-asn ./test/GeoLite2-ASN-Test.mmdb \
             -trusted-header X-Real-IP -template mytemplate.tmpl

Download

Download latest version from https://github.com/dcarrillo/whatismyip/releases

Docker

An ultra-light (~9MB) image is available.

Run a container locally using test databases

make docker-run

From Docker Hub

docker run --tty --interactive --rm \
    -v $PWD/<path to city database>:/tmp/GeoIP2-City-Test.mmdb:ro \
    -v $PWD/<path to ASN database>:/tmp/GeoLite2-ASN-Test.mmdb:ro -p 8080:8080 \
    dcarrillo/whatismyip:latest \
      -geoip2-city /tmp/GeoIP2-City-Test.mmdb \
      -geoip2-asn /tmp/GeoLite2-ASN-Test.mmdb