Use the databases
Download an InternetData database with a free account's key, look addresses up on your own servers, and keep the file current every day.
A database answers on your own servers, with no request per lookup. This walks through IP Country, one of the Open databases every account may download for free.
1. Get a key that may download
Sign up; the key the console makes for you may look up and download. A key needs the db.download scope to download.
export INTERNETDATA_API_KEY="YOUR_API_KEY"2. Download the file
curl -L -o ip_country_v1.mmdb \
"https://internetdata.io/api/v2/database/download?id=ip_country_v1&format=mmdb&apikey=$INTERNETDATA_API_KEY"-L follows the redirect to the file. Every database comes as CSV too (format=csvgz); Formats says how each is laid out.
3. Look an address up locally
An MMDB answers an address in microseconds with any MMDB reader:
# pip install maxminddb
import maxminddb
with maxminddb.open_database("ip_country_v1.mmdb") as reader:
record = reader.get("8.8.8.8")
print(record["country"], record["currency_code"]) # US USD// npm install maxmind
import maxmind from 'maxmind';
const countries = await maxmind.open('ip_country_v1.mmdb');
const record = countries.get('8.8.8.8');
console.log(record?.country); // US// go get github.com/oschwald/maxminddb-golang/v2
db, err := maxminddb.Open("ip_country_v1.mmdb")
if err != nil {
log.Fatal(err)
}
defer db.Close()
var record struct {
Country string `maxminddb:"country"`
CurrencyCode string `maxminddb:"currency_code"`
}
if err := db.Lookup(netip.MustParseAddr("8.8.8.8")).Decode(&record); err != nil {
log.Fatal(err)
}
fmt.Println(record.Country) // US4. Keep it current
IP Country is rebuilt every day, like most of the catalog. Fetch it on a schedule, or have each new build come to you:
- Metadata says when the current build was made, so a daily job can skip a file that has not changed.
- Checksums gives each file's SHA-256 to check once it lands.
- Webhooks call your endpoint when a build is out, and S3, Google Cloud Storage, Azure and SFTP take each build into your own storage.
The rest of the catalog
The Open databases are free for every account: IP Country with its currency, flag and timezone files, IP ASN, ASN, Anycast IP, the bogon lists, Tor IP and Relay IP. The other databases are licensed: ask us which suit you, and the Database Reference has each one's columns and a sample.