Coder Social home page Coder Social logo

geoip2's Introduction

Software License Go Report Card Go Doc

GeoIP2 Reader for Go

This library reads MaxMind GeoIP2 databases.

Inspired by oschwald/geoip2-golang.

Installation

go get github.com/IncSW/geoip2

Quick Start

import "github.com/IncSW/geoip2"

reader, err := geoip2.NewCityReaderFromFile("path/to/GeoIP2-City.mmdb")
if err != nil {
	panic(err)
}
record, err := reader.Lookup(net.ParseIP("81.2.69.142"))
if err != nil {
	panic(err)
}
println(record.Continent.Names["zh-CN"]) // 欧洲
println(record.City.Names["pt-BR"]) // Wimbledon
if len(record.Subdivisions) != 0 {
	println(record.Subdivisions[0].Names["en"]) // England
}
println(record.Country.Names["ru"]) // Великобритания
println(record.Country.ISOCode) // GB
println(record.Location.TimeZone) // Europe/London
println(record.Country.GeoNameID) // 2635167, https://www.geonames.org/2635167

Performance

city-24                          342847    2981 ns/op   2032 B/op    12 allocs/op
city_parallel-24                4477626     269 ns/op   2032 B/op    12 allocs/op
isp-24                          3539738     336 ns/op     64 B/op     1 allocs/op
isp_parallel-24                46938070    25.7 ns/op     64 B/op     1 allocs/op
connection_type-24              8759110     133 ns/op      0 B/op     0 allocs/op
connection_type_parallel-24   142261742    8.34 ns/op      0 B/op     0 allocs/op
city-24                          109092   10717 ns/op   2848 B/op   103 allocs/op
city_parallel-24                 662510    1718 ns/op   2848 B/op   103 allocs/op
isp-24                          1688287     705 ns/op    112 B/op     4 allocs/op
isp_parallel-24                14285560    84.4 ns/op    112 B/op     4 allocs/op
connection_type-24              3883234     305 ns/op     32 B/op     2 allocs/op
connection_type_parallel-24    34284831    32.1 ns/op     32 B/op     2 allocs/op

Supported databases types

Country

  • GeoIP2-Country
  • GeoLite2-Country
  • DBIP-Country
  • DBIP-Country-Lite

City

  • GeoIP2-City
  • GeoLite2-City
  • GeoIP2-Enterprise
  • DBIP-City-Lite

ISP

  • GeoIP2-ISP

ASN

  • GeoLite2-ASN
  • DBIP-ASN-Lite
  • DBIP-ASN-Lite (compat=GeoLite2-ASN)

Connection Type

  • GeoIP2-Connection-Type

Anonymous IP

  • GeoIP2-Anonymous-IP

Domain

  • GeoIP2-Domain

License

MIT License.

geoip2's People

Contributors

incsw avatar rianby64 avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.