Reorganize packages

This commit is contained in:
2021-10-21 12:36:01 +02:00
parent a71ff52ab4
commit 94e7faae78
15 changed files with 24 additions and 24 deletions

35
honeypot/ssh/geolocate.go Normal file
View File

@@ -0,0 +1,35 @@
package ssh
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
}