apiary/honeypot/geolocate.go
2021-04-10 07:58:01 +02:00

25 lines
346 B
Go

package honeypot
import (
_ "embed"
"net"
"github.com/oschwald/geoip2-golang"
)
//go:embed Geoacumen-Country.mmdb
var mmdb []byte
func LookupCountry(ip net.IP) string {
db, err := geoip2.FromBytes(mmdb)
if err != nil {
return "??"
}
country, err := db.Country(ip)
if err != nil {
return "??"
}
return country.Country.IsoCode
}