Documentation
¶
Overview ¶
Package ipres provider an IP resolver that returns information about an IP address.
Index ¶
Constants ¶
const ( CountryIPv4URL = "https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-country/geolite2-country-ipv4.csv" CountryIPv6URL = "https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-country/geolite2-country-ipv6.csv" ASNIPv4URL = "https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-asn/geolite2-asn-ipv4.csv" ASNIPv6URL = "https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-asn/geolite2-asn-ipv6.csv" )
URLs of the CSV IP location databases.
const AS0 uint32 = 0
AS0 represents the default ASN value for unknown addresses.
Variables ¶
var ( ErrRecordLength = errors.New("invalid record length") ErrInvalidANS = errors.New("invalid ASN") )
ErrRecordLength is returned when a CSV record has an unexpected length.
Functions ¶
This section is empty.
Types ¶
type DBRecord ¶
type DBRecord struct { StartIP netip.Addr EndIP netip.Addr Resolution Resolution }
DBRecord contains the information of a database record.
type ResTree ¶
type ResTree = itree.ITree[netip.Addr, Resolution]
ResTree is a type alias for an interval tree that maps IP addresses to resolutions.
type Resolution ¶
type Resolution struct { CountryCode string // ISO 3166-1 alpha-2 country code Organization string // Organization name ASN uint32 // Autonomous System Number }
Resolution contains the result of resolving an IP address.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver is an IP resolver that returns information about an IP address.
func (*Resolver) Resolve ¶
func (r *Resolver) Resolve(ip netip.Addr) Resolution
Resolve resolves the given IP address to a country code and an ASN.
It is the caller's responsibility to check if the IP is valid.
If the country of the IP is not found, the CountryCode field of the result will be an empty string. If the ASN of the IP is not found, the ASN field of the result will be zero.
The Organization field is present for informational purposes only. It is not used by the rules engine.