https://github.com/alecthomas/geoip
A pure Go interface to the free MaxMind GeoIP database
https://github.com/alecthomas/geoip
Last synced: over 1 year ago
JSON representation
A pure Go interface to the free MaxMind GeoIP database
- Host: GitHub
- URL: https://github.com/alecthomas/geoip
- Owner: alecthomas
- Created: 2013-06-12T21:14:10.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2024-01-01T08:56:34.000Z (over 2 years ago)
- Last Synced: 2025-02-28T02:11:28.681Z (over 1 year ago)
- Language: Go
- Size: 3.19 MB
- Stars: 39
- Watchers: 6
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A pure Go interface to the free [MaxMind GeoIP](http://dev.maxmind.com/geoip/legacy/downloadable) database
This package provides fast lookups of country by IP address.
This implementation compiles an optimized version of the database into Go (using [gobundle](http://github.com/alecthomas/gobundle)), and so does not rely on external files. The in-memory table size is around ~800KB.
### Caveats
Currently only IPv4->country lookups are supported.
### Installation
```bash
$ # Library
$ go get github.com/alecthomas/geoip
$ # Command
$ go get github.com/alecthomas/geoip/cmd/geoip
```
### Usage
Command line usage:
```bash
$ geoip 1.1.1.1
Australia (AU)
```
See [GoDoc](http://godoc.org/github.com/alecthomas/geoip) for API documentation.
```go
geo, err := geoip.New()
country := geo.Lookup(net.ParseIP("1.1.1.1"))
fmt.Printf("%s\n", country)
```
### Performance
A benchmark is included (`go test -bench='.*'`). On my 2GHz Core i7 each lookup takes around 550ns.
### Updating the database
The package can be rebuilt with an updated datbase with the following commands:
```bash
$ curl -O http://www.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
$ unzip GeoIPCountryCSV.zip
$ make
```
### Legal
This product includes GeoLite data created by MaxMind, available from [maxmind.com](http://www.maxmind.com).