apiary/honeypot/geolocate.go

25 lines
346 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
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
}