How to Find GeoIP from an IP?

There are two components of getting detailed info about an IP.

  • A GeoIP database
  • A library to look up the DB

These DBs are not free and have a proprietary format. So a library is required to perform lookups.
One such format is MaxMind and used by GeoIP2 & GeoLite2 DBs.

More @

A test program to get detailed IP information

$ cat mytest.go                                                                                                                                          [18:46:01]
//package maxminddb_test
package main

import (


// This example shows how to decode to a struct
func ExampleReader_Lookup_struct() {
        db, err := maxminddb.Open("./tests/static/GeoIP2-City.mmdb")
        if err != nil {
        defer db.Close()

        ip := net.ParseIP("")

        var record interface{}
        err = db.Lookup(ip, &record)
        if err != nil {

func main() {

Note that the lookup assumes an interface type. The reason is that the API allows the application to specify what fields to lookup.

You can decide on the record structure after dumping the complete info and picking what you need.


Written with StackEdit.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: