A HTTP API for geodb
- Create a new account with Maxmind for Geolite2
- Generate a Maxmind License key as instructed here.
- Export the generated Key:
export MAXMIND_KEY="abcdefghijklmnop"
- Databases are as defined here
- Determine a path at which these databases are going to be downloaded. This app will require approx 85MiB of free space for DBs only
- Export above path:
export GL2_DBDIR="/tmp/dbdir"
- This application can be run with or without auth.
- If auth is needed continue else jump to step 11
- Create a file with one secret key in each line. Something like this:
CBOI7AIHQcAKhaHVol
7toCW4ndOvNy0ssSot
L44eRv07k2KwndvLQm
EGwSQtwsPjzv1IO75Z
h2UvAAs63ZjhYnISjn
- Now export above file:
export GEODB_AUTH_FILE="/tmp/geodb-server-auth.txt"
Any of the keys, one per line, from this file can be used for auth
- Test the API (more in the API section below) out for an IP:
curl -H "Authorization:CBOI7AIHQcAKhaHVol" http://localhost:40000/country/ip/1.32.128.0
curl http://localhost:40000/country/ip/1.32.128.0
- This application uses protobufs and responds in protobufs only. The proto files are
available in
src/protos
. Naturally to build those you'll need to install protoc. - Once it's available in
PATH
- just docargo build
orcargo build --release
This application has 4 APIs. All of them are GET HTTP Requests and each returns one
of the protobuf Message
s defined in src/protos/geo.proto
.
- [GET]
/country/ip/:ip
Given some IP(v4|v6) this responds with the proto message Country
.
Responds with a 400 Bad Request in case no mapping is found
- [GET]
/country/iso/:iso
Given the ISO2 code, as defined in ISO 3166,
of any country this route also responds with the proto message Country
.
400 Bad Request if the code is not found.
- [GET]
/city/:ip
Given some IP(v4|v6) this responds with the proto message City
.
400 Bad Request if not found.
- [GET]
/asn/:ip
Given some IP(v4|v6) this responds with the proto message ASN
.
400 Bad Request if not found.