// GetOrg takes an IPv4 address string and returns the org name for that IP. // Requires the geoip org database func (gi *GeoIP) GetOrg(ip string) string { if gi.db == nil { return "" } cip := C.CString(ip) cname := C.GeoIP_name_by_addr(gi.db, cip) C.free(unsafe.Pointer(cip)) if cname != nil { rets := C.GoString(cname) return rets } return "" }
// Works on the ASN, Netspeed, Organization and probably other // databases, takes and IP string and returns a "name" and the // netmask. func (gi *GeoIP) GetName(ip string) (name string, netmask int) { if gi.db == nil { return } gi.mu.Lock() defer gi.mu.Unlock() cip := C.CString(ip) defer C.free(unsafe.Pointer(cip)) cname := C.GeoIP_name_by_addr(gi.db, cip) if cname != nil { name = C.GoString(cname) defer C.free(unsafe.Pointer(cname)) netmask = int(C.GeoIP_last_netmask(gi.db)) return } return }