Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/oschwald/geoip2-golang"
|
||||
"net"
|
||||
)
|
||||
|
||||
func HandleGeoIPCommand(ipAddress string, dbPath string) (string, error) {
|
||||
db, err := geoip2.Open(dbPath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error opening GeoIP database: %v", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
ip := net.ParseIP(ipAddress)
|
||||
record, err := db.City(ip)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error looking up IP address: %v", err)
|
||||
}
|
||||
|
||||
if record.Country.IsoCode != "" {
|
||||
return fmt.Sprintf("IP: %s, Country: %s", ipAddress, record.Country.IsoCode), nil
|
||||
}
|
||||
|
||||
return "Country not found", nil
|
||||
}
|
||||
Reference in New Issue
Block a user