# README
geoip-legacy
A port of libGeoIP from C to pure Go. It supports IPv4 and IPv6 country databases.
Example usage
For extensive examples, see geoip_test.go, but here is a relatively simple example. GetCountryByAddr supports IP addresses and can use the net
package in the standard library to resolve a domain to an IP and look up the IP in the database.
IPv4-only DB example:
db, err := geoiplegacy.OpenDB("/usr/share/GeoIP/GeoIP.dat", nil)
if err != nil {
panic(err)
}
country, err = db.GetCountryByAddr("8.8.8.8")
if err != nil {
panic(err)
}
fmt.Printf("Country code: %s\nCountry name: %s\n", country.Code, country.NameUTF8)
IPv6-only DB example:
db, err := geoiplegacy.OpenDB("/usr/share/GeoIP/GeoIPv6.dat", &GeoIPOptions{
IsIPv6: true,
})
if err != nil {
panic(err)
}
country, err = db.GetCountryByAddr("2801::1")
if err != nil {
panic(err)
}
fmt.Printf("Country code: %s\nCountry name: %s\n", country.Code, country.NameUTF8)
Combined DB example usage
The above examples are only usable for looking up either IPv4 or IPv6 addresses. To be able to look up both, you can use a CombinedDB
.
Example usage:
db, err := geoiplegacy.OpenCombinedDB("/usr/share/GeoIP/GeoIP.dat", "/usr/share/GeoIP/GeoIPv6.dat")
if err != nil {
panic(err)
}
country, err = db.GetCountryByAddr("8.8.8.8")
// ...
country, err = db.GetCountryByAddr("2801::1")
// ...
country, err = db.GetCountryByAddr("google.com")
// ...
A regular DB can also handle domains, but a domain may or may not resolve to an IPv6 address, so a CombinedDB
is recommended.
# Functions
OpenCombinedDB opens the given IPv4 and IPv6 databases and returns a combined database for automatically determining which database file to use when looking up an address.
OpenDB opens and returns the MaxMind GeoIP v1 database, returning the database and any errors.
# Constants
No description provided by the author
No description provided by the author
GeoIPProxyTypes enum.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
unused but gaps are not allowed.
No description provided by the author
No description provided by the author
No description provided by the author
unsupported.
unused but gaps are not allowed.
unsupported.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GeoIPDBTypes enum.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GeoIPNetspeedValues enum.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
CombinedDB is a wrapper around the DB struct, allowing automatic IPv4 and IPv6 GeoIP usage.
CountryResult is the result of scanning the database for the location of a network address.
DB represents a legacy GeoIP database, usually having a .dat extension.
GeoIPOptions are used when reading the database file.
# Interfaces
GeoIPDB can be used by functions for geoip-legacy DB and CombinedDB.
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author