ipinfo

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CountryCode

type CountryCode string

func (CountryCode) String

func (cc CountryCode) String() string

type IPInfo

type IPInfo struct {
	CountryCode CountryCode
	ASN         int
}

func GetIPInfoFromAddr

func GetIPInfoFromAddr(ip2info IPInfoMap, addr net.Addr) (IPInfo, error)

GetIPInfoFromAddr is a helper function to extract the IP address from the net.Addr and call IPInfoMap.GetIPInfo. It uses special country codes to indicate errors:

  • "XA": failed to extract the IP from the address ("A" is for "Address").
  • "XL": IP is not global ("L" is for "Local").
  • "XD": database error looking up the country code ("D" is for "DB").
  • "ZZ": lookup returned an empty country code (same as the Unicode unknown location).

func GetIPInfoFromIP

func GetIPInfoFromIP(ip2info IPInfoMap, ip net.IP) (IPInfo, error)

GetIPInfoFromIP is a helper function to call IPInfoMap.GetIPInfo using a net.IP. It uses special country codes to indicate errors:

  • "XL": IP is not global ("L" is for "Local").
  • "XD": database error looking up the country code ("D" is for "DB").
  • "ZZ": lookup returned an empty country code (same as the Unicode unknown location).

type IPInfoMap

type IPInfoMap interface {
	GetIPInfo(net.IP) (IPInfo, error)
}

type MMDBIPInfoMap

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

MMDBIpInfoMap is an ipinfo.IPInfoMap that uses MMDB files to lookup IP information.

func NewMMDBIPInfoMap

func NewMMDBIPInfoMap(countryDBPath string, asnDBPath string) (*MMDBIPInfoMap, error)

NewMMDBIPInfoMap creates an ipinfo.IPInfoMap that uses the MMDB at countryDBPath to lookup IP Country information and the MMDB at asnDBPath to lookup IP ASN information. Either may be "", in which case you won't get the corresponding information in the IPInfo.

func (*MMDBIPInfoMap) Close

func (ip2info *MMDBIPInfoMap) Close() error

func (*MMDBIPInfoMap) GetIPInfo

func (ip2info *MMDBIPInfoMap) GetIPInfo(ip net.IP) (IPInfo, error)

GetIPInfo implements IPInfoMap.GetIPInfo.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL