geoip: github.com/abh/geoip Index | Files | Directories

package geoip

import "github.com/abh/geoip"

Go (cgo) interface to libgeoip

Index

Package Files

const.go geoip.go

Constants

const (
    GEOIP_COUNTRY_EDITION            = 1
    GEOIP_REGION_EDITION_REV0        = 7
    GEOIP_CITY_EDITION_REV0          = 6
    GEOIP_ORG_EDITION                = 5
    GEOIP_ISP_EDITION                = 4
    GEOIP_CITY_EDITION_REV1          = 2
    GEOIP_REGION_EDITION_REV1        = 3
    GEOIP_PROXY_EDITION              = 8
    GEOIP_ASNUM_EDITION              = 9
    GEOIP_NETSPEED_EDITION           = 10
    GEOIP_DOMAIN_EDITION             = 11
    GEOIP_COUNTRY_EDITION_V6         = 12
    GEOIP_LOCATIONA_EDITION          = 13
    GEOIP_ACCURACYRADIUS_EDITION     = 14
    GEOIP_CITYCONFIDENCE_EDITION     = 15
    GEOIP_CITYCONFIDENCEDIST_EDITION = 16
    GEOIP_LARGE_COUNTRY_EDITION      = 17
    GEOIP_LARGE_COUNTRY_EDITION_V6   = 18
    GEOIP_ASNUM_EDITION_V6           = 21
    GEOIP_ISP_EDITION_V6             = 22
    GEOIP_ORG_EDITION_V6             = 23
    GEOIP_DOMAIN_EDITION_V6          = 24
    GEOIP_LOCATIONA_EDITION_V6       = 25
    GEOIP_REGISTRAR_EDITION          = 26
    GEOIP_REGISTRAR_EDITION_V6       = 27
    GEOIP_USERTYPE_EDITION           = 28
    GEOIP_USERTYPE_EDITION_V6        = 29
    GEOIP_CITY_EDITION_REV1_V6       = 30
    GEOIP_CITY_EDITION_REV0_V6       = 31
    GEOIP_NETSPEED_EDITION_REV1      = 32
    GEOIP_NETSPEED_EDITION_REV1_V6   = 33
)

func GetRegionName

func GetRegionName(countryCode, regionCode string) string

Returns the region name given a country code and region code

func SetCustomDirectory

func SetCustomDirectory(dir string)

SetCustomDirectory sets the default location for the GeoIP .dat files used when calling OpenType()

type GeoIP

type GeoIP struct {
    // contains filtered or unexported fields
}

func Open

func Open(files ...string) (*GeoIP, error)

Opens a GeoIP database by filename, all formats supported by libgeoip are supported though there are only functions to access some of the databases in this API. The database is opened in MEMORY_CACHE mode, if you need to optimize for memory instead of performance you should change this. If you don't pass a filename, it will try opening the database from a list of common paths.

func OpenType

func OpenType(dbType int) (*GeoIP, error)

OpenType opens a specified GeoIP database type in the default location. Constants are defined for each database type (for example GEOIP_COUNTRY_EDITION).

func (*GeoIP) GetCountry

func (gi *GeoIP) GetCountry(ip string) (cc string, netmask int)

Takes an IPv4 address string and returns the country code for that IP and the netmask for that IP range.

func (*GeoIP) GetCountry_v6

func (gi *GeoIP) GetCountry_v6(ip string) (cc string, netmask int)

GetCountry_v6 works the same as GetCountry except for IPv6 addresses, be sure to load a database with IPv6 data to get any results.

func (*GeoIP) GetName

func (gi *GeoIP) GetName(ip string) (name string, netmask int)

Works on the ASN, Netspeed, Organization and probably other databases, takes and IP string and returns a "name" and the netmask.

func (*GeoIP) GetNameV6

func (gi *GeoIP) GetNameV6(ip string) (name string, netmask int)

Same as GetName() but for IPv6 addresses.

func (*GeoIP) GetOrg

func (gi *GeoIP) GetOrg(ip string) string

Takes an IPv4 address string and returns the organization name for that IP. Requires the GeoIP organization database.

func (*GeoIP) GetRecord

func (gi *GeoIP) GetRecord(ip string) *GeoIPRecord

Returns the "City Record" for an IP address. Requires the GeoCity(Lite) database - http://www.maxmind.com/en/city

func (*GeoIP) GetRegion

func (gi *GeoIP) GetRegion(ip string) (string, string)

Returns the country code and region code for an IP address. Requires the GeoIP Region database.

type GeoIPRecord

type GeoIPRecord struct {
    CountryCode  string
    CountryCode3 string
    CountryName  string
    Region       string
    City         string
    PostalCode   string
    Latitude     float32
    Longitude    float32
    // DMACode       int
    AreaCode      int
    CharSet       int
    ContinentCode string
}

Directories

PathSynopsis
ex

Package geoip imports 7 packages (graph) and is imported by 25 packages. Updated 2014-03-22. Refresh now. Tools for package owners.