1
无
This commit is contained in:
33
modules/MmdbQuery.go
Normal file
33
modules/MmdbQuery.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"github.com/IncSW/geoip2"
|
||||
"net"
|
||||
)
|
||||
|
||||
type IpInfo struct {
|
||||
Ip string `json:"ip"`
|
||||
CountryIsoCode string `json:"Country_Iso_Code"`
|
||||
CountryName string `json:"Country_Name"`
|
||||
City string `json:"City"`
|
||||
TimeZone string `json:"Time_Zone"`
|
||||
}
|
||||
|
||||
func MmdbQueryIP(ip string) IpInfo {
|
||||
reader, err := geoip2.NewCityReaderFromFile("./db/GeoLite2-City.mmdb")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
record, err := reader.Lookup(net.ParseIP(ip))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
GetIpInfo := IpInfo{
|
||||
Ip: ip,
|
||||
CountryIsoCode: record.Country.ISOCode,
|
||||
CountryName: record.Country.Names["en"],
|
||||
City: record.City.Names["en"],
|
||||
TimeZone: record.Location.TimeZone,
|
||||
}
|
||||
return GetIpInfo
|
||||
}
|
||||
Reference in New Issue
Block a user