apiary/honeypot/geolocate.go

27 lines
488 B
Go
Raw Normal View History

2021-04-10 05:58:01 +00:00
package honeypot
import (
_ "embed"
"net"
"github.com/oschwald/geoip2-golang"
)
//go:embed Geoacumen-Country.mmdb
var mmdb []byte
2021-04-10 09:59:10 +00:00
func (s *HoneypotServer) LookupCountry(ip net.IP) string {
2021-04-10 05:58:01 +00:00
db, err := geoip2.FromBytes(mmdb)
if err != nil {
2021-04-10 09:59:10 +00:00
s.Logger.Warnw("Error opening geoip database", "error", err)
2021-04-10 05:58:01 +00:00
return "??"
}
country, err := db.Country(ip)
if err != nil {
2021-04-10 09:59:10 +00:00
s.Logger.Warnw("Error doing geoip lookup", "error", err)
2021-04-10 05:58:01 +00:00
return "??"
}
return country.Country.IsoCode
}