27 lines
488 B
Go
27 lines
488 B
Go
package honeypot
|
|
|
|
import (
|
|
_ "embed"
|
|
"net"
|
|
|
|
"github.com/oschwald/geoip2-golang"
|
|
)
|
|
|
|
//go:embed Geoacumen-Country.mmdb
|
|
var mmdb []byte
|
|
|
|
func (s *HoneypotServer) LookupCountry(ip net.IP) string {
|
|
db, err := geoip2.FromBytes(mmdb)
|
|
if err != nil {
|
|
s.Logger.Warnw("Error opening geoip database", "error", err)
|
|
return "??"
|
|
}
|
|
|
|
country, err := db.Country(ip)
|
|
if err != nil {
|
|
s.Logger.Warnw("Error doing geoip lookup", "error", err)
|
|
return "??"
|
|
}
|
|
return country.Country.IsoCode
|
|
}
|