Reorganize packages
This commit is contained in:
35
honeypot/ssh/geolocate.go
Normal file
35
honeypot/ssh/geolocate.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user