ip

package
v0.0.0-...-b628505 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(req *http.Request) string

func ClientPublicIP

func ClientPublicIP(req *http.Request) string

func ContentType

func ContentType(req *http.Request) string

ContentType returns the Content-Type header of the request.

func HasLocalIP

func HasLocalIP(ip net.IP) bool

func HasLocalIPAddr

func HasLocalIPAddr(ip string) bool

func IsWebsocket

func IsWebsocket(req *http.Request) bool

func LongToIP

func LongToIP(i uint) (net.IP, error)

func LongToIPString

func LongToIPString(i uint) (string, error)

func RemoteIP

func RemoteIP(req *http.Request) string

func StringToLong

func StringToLong(ip string) (uint, error)

func ToLong

func ToLong(ip net.IP) (uint, error)

Types

type Filter

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

func New

func New(opts Options) *Filter

New constructs IPFilter instance without downloading DB.

func (*Filter) AllowIP

func (f *Filter) AllowIP(ip string) bool

func (*Filter) Allowed

func (f *Filter) Allowed(ipstr string) bool

Allowed returns if a given IP can pass through the filter

func (*Filter) BlockIP

func (f *Filter) BlockIP(ip string) bool

func (*Filter) Blocked

func (f *Filter) Blocked(ip string) bool

Blocked returns if a given IP can NOT pass through the filter

func (*Filter) NetAllowed

func (f *Filter) NetAllowed(ip net.IP) bool

NetAllowed returns if a given net.IP can pass through the filter

func (*Filter) NetBlocked

func (f *Filter) NetBlocked(ip net.IP) bool

NetBlocked returns if a given net.IP can NOT pass through the filter

func (*Filter) ToggleDefault

func (f *Filter) ToggleDefault(allowed bool)

ToggleDefault alters the default setting

func (*Filter) ToggleIP

func (f *Filter) ToggleIP(str string, allowed bool) bool

type Options

type Options struct {
	//AllowedIPs allowed IPs
	AllowedIPs []string
	//BlockedIPs blocked IPs
	BlockedIPs []string

	//block by default (defaults to allow)
	BlockByDefault bool
}

Jump to

Keyboard shortcuts

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