ip

package
v6.18.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: AGPL-3.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CFConnectingIP is an HeaderParser.
	// https://support.cloudflare.com/hc/en-us/articles/206776727-What-is-True-Client-IP-
	CFConnectingIP = HeaderParser{"CF-Connecting-IP", parseXForwardedForHeader}

	// TrueClientIP is an HeaderParser.
	TrueClientIP = HeaderParser{"True-Client-IP", parseXForwardedForHeader}

	// XForwardedFor is an HeaderParser.
	XForwardedFor = HeaderParser{"X-Forwarded-For", parseXForwardedForHeader}

	// Forwarded is an HeaderParser.
	Forwarded = HeaderParser{"Forwarded", parseForwardedHeader}

	// XRealIP is an HeaderParser.
	XRealIP = HeaderParser{"X-Real-IP", parseXRealIPHeader}

	// DefaultHeaderParser is a list of headers and corresponding parsers to look up the real client IP.
	// They will be check in order, the first non-empty one will be picked,
	// or else the remote address is selected.
	DefaultHeaderParser = []HeaderParser{
		CFConnectingIP,
		TrueClientIP,
		XForwardedFor,
		Forwarded,
		XRealIP,
	}
)

Functions

func Get

func Get(r *http.Request, parser []HeaderParser, allowed []net.IPNet) string

Get returns the IP from given request. It will try to extract the real client IP from headers if possible.

Types

type Filter

type Filter interface {
	// Update updates the filter list for given plain IP addresses and IP address ranges (v4 and v6).
	Update([]string, []string, []string, []string, []Range, []Range)

	// Ignore reports whether an IP address should be ignored.
	Ignore(string) bool
}

Filter filters requests using the IP address.

type HeaderParser

type HeaderParser struct {
	Header string
	Parser ParseHeaderFunc
}

HeaderParser parses a header to extract the real client IP address.

type ParseHeaderFunc

type ParseHeaderFunc func(string) string

ParseHeaderFunc parses and validates an IP address from a header. It must return an empty string if the header or contained IP address is invalid.

type Range

type Range struct {
	From string
	To   string
}

Range is an IP address range.

type Udger

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

Udger implements the Filter interface.

func NewUdger

func NewUdger(accessKey, downloadPath, downloadURL string) *Udger

NewUdger creates a new Filter using the IP lists provided by udger.com. The download URL is optional and will be set to the default if empty. It must contain "%s" for the access key.

func (*Udger) DownloadAndUpdate

func (u *Udger) DownloadAndUpdate() error

DownloadAndUpdate downloads and updates the IP list from udger.com.

func (*Udger) Ignore

func (u *Udger) Ignore(ip string) bool

Ignore implements the Filter interface.

func (*Udger) Update

func (u *Udger) Update(ipsV4, ipsV6, whitelistIpV4, whitelistIpV6 []string, rangesV4, rangesV6 []Range)

Update implements the Filter interface.

Jump to

Keyboard shortcuts

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