From 3eaa7d239700ec8092a1e97d910ff5ecdb340177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 10 Apr 2021 12:12:08 +0200 Subject: [PATCH] Use different package for geoip --- go.mod | 3 ++- go.sum | 2 -- honeypot/geolocate.go | 14 ++++++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index f735684..587dc5f 100644 --- a/go.mod +++ b/go.mod @@ -10,9 +10,10 @@ require ( github.com/go-chi/chi/v5 v5.0.2 github.com/google/uuid v1.2.0 github.com/jackc/pgx/v4 v4.11.0 - github.com/oschwald/geoip2-golang v1.5.0 + github.com/oschwald/maxminddb-golang v1.8.0 github.com/pelletier/go-toml v1.9.0 github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/stretchr/testify v1.7.0 // indirect github.com/urfave/cli/v2 v2.3.0 go.uber.org/zap v1.13.0 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 diff --git a/go.sum b/go.sum index f22fee4..3180f65 100644 --- a/go.sum +++ b/go.sum @@ -260,8 +260,6 @@ github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxS github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= -github.com/oschwald/geoip2-golang v1.5.0 h1:igg2yQIrrcRccB1ytFXqBfOHCjXWIoMv85lVJ1ONZzw= -github.com/oschwald/geoip2-golang v1.5.0/go.mod h1:xdvYt5xQzB8ORWFqPnqMwZpCpgNagttWdoZLlJQzg7s= github.com/oschwald/maxminddb-golang v1.8.0 h1:Uh/DSnGoxsyp/KYbY1AuP0tYEwfs0sCph9p/UMXK/Hk= github.com/oschwald/maxminddb-golang v1.8.0/go.mod h1:RXZtst0N6+FY/3qCNmZMBApR19cdQj43/NM9VkrNAis= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= diff --git a/honeypot/geolocate.go b/honeypot/geolocate.go index e18c9d7..18969ff 100644 --- a/honeypot/geolocate.go +++ b/honeypot/geolocate.go @@ -4,23 +4,29 @@ import ( _ "embed" "net" - "github.com/oschwald/geoip2-golang" + "github.com/oschwald/maxminddb-golang" ) //go:embed Geoacumen-Country.mmdb var mmdb []byte func (s *HoneypotServer) LookupCountry(ip net.IP) string { - db, err := geoip2.FromBytes(mmdb) + db, err := maxminddb.FromBytes(mmdb) if err != nil { s.Logger.Warnw("Error opening geoip database", "error", err) return "??" } - country, err := db.Country(ip) + var record struct { + Country struct { + ISOCode string `maxminddb:"iso_code"` + } `maxminddb:"country"` + } + + err = db.Lookup(ip, &record) if err != nil { s.Logger.Warnw("Error doing geoip lookup", "error", err) return "??" } - return country.Country.IsoCode + return record.Country.ISOCode }