We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Something like this:
//mmdb ConnectionType func GetConnectionType(ipStr string) string { ipObj := net.ParseIP(ipStr) reader := dbReader("./assets/GeoIP2-Connection-Type.mmdb") defer reader.Close() record, err := reader.ConnectionType(ipObj) if err != nil { logBadIp(err) return "unknown" } else { return record.ConnectionType } }
//mmdb ISP func GetIsp(ipStr string) (string, string) { ipObj := net.ParseIP(ipStr) dbIsp := dbReader("./assets/GeoIP2-ISP.mmdb") defer dbIsp.Close() record, err := dbIsp.ISP(ipObj) if err != nil { logBadIp(err) return "unknown", "unknown" } else { return record.ISP, record.Organization } }
func dbReader(mmdbPath string) *geoip2.Reader { dbConn, err := geoip2.Open(mmdbPath) if err != nil { log.Println(err) } return dbConn } func logBadIp(err error) { log.Println(err) log.Println("bad IP") }
The text was updated successfully, but these errors were encountered:
Awesome, thank you so much for sharing these examples. I appreciate it.
Sorry, something went wrong.
No branches or pull requests
Something like this:
//mmdb ConnectionType
func GetConnectionType(ipStr string) string {
ipObj := net.ParseIP(ipStr)
reader := dbReader("./assets/GeoIP2-Connection-Type.mmdb")
defer reader.Close()
record, err := reader.ConnectionType(ipObj)
if err != nil {
logBadIp(err)
return "unknown"
} else {
return record.ConnectionType
}
}
//mmdb ISP
func GetIsp(ipStr string) (string, string) {
ipObj := net.ParseIP(ipStr)
dbIsp := dbReader("./assets/GeoIP2-ISP.mmdb")
defer dbIsp.Close()
record, err := dbIsp.ISP(ipObj)
if err != nil {
logBadIp(err)
return "unknown", "unknown"
} else {
return record.ISP, record.Organization
}
}
func dbReader(mmdbPath string) *geoip2.Reader {
dbConn, err := geoip2.Open(mmdbPath)
if err != nil {
log.Println(err)
}
return dbConn
}
func logBadIp(err error) {
log.Println(err)
log.Println("bad IP")
}
The text was updated successfully, but these errors were encountered: