Use different package for geoip
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user