36 lines
658 B
Go
36 lines
658 B
Go
package honeypot
|
|
|
|
import (
|
|
_ "embed"
|
|
"net"
|
|
|
|
"github.com/oschwald/maxminddb-golang"
|
|
)
|
|
|
|
//go:embed Geoacumen-Country.mmdb
|
|
var mmdb []byte
|
|
|
|
func (s *HoneypotServer) LookupCountry(ip net.IP) string {
|
|
db, err := maxminddb.FromBytes(mmdb)
|
|
if err != nil {
|
|
s.Logger.Warnw("Error opening geoip database", "error", err)
|
|
return "??"
|
|
}
|
|
|
|
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 "??"
|
|
}
|
|
if record.Country.ISOCode == "None" {
|
|
return "??"
|
|
}
|
|
return record.Country.ISOCode
|
|
}
|