iputil

package
v0.0.0-...-6bcf8dd Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BigIntToIPv6

func BigIntToIPv6(b *big.Int) net.IP

func GetHostIPs

func GetHostIPs() ([]net.IP, error)

GetHostIPs returns a list of IP addresses of all host's interfaces.

func HLintToIPv6

func HLintToIPv6(high uint64, low uint64) net.IP

func IPv6ToBigInt

func IPv6ToBigInt(ip net.IP) *big.Int

func IPv6ToHLint

func IPv6ToHLint(ip net.IP) (uint64, uint64)

func IntToIPv4

func IntToIPv4(ip uint32) net.IP

convert a uint32 to an ipv4

func IpInMasks

func IpInMasks(ip net.IP, masks []net.IPNet) bool

checks if a net.IP is in a list of net.IPNet

func Ipv4ToInt

func Ipv4ToInt(ip net.IP) (uint32, error)

Convert an ipv4 to a uint32

func IsCIDR

func IsCIDR(s string) bool

func IsIPv4

func IsIPv4(str string) bool

func IsIPv6

func IsIPv6(str string) bool

func IsMAC

func IsMAC(str string) bool

func IsPublicIP

func IsPublicIP(ip net.IP, privateMasks []net.IPNet) bool

IsPublicIP returns true if the given IP can be routed on the Internet.

func LastAddress

func LastAddress(n *net.IPNet) net.IP

Return the final address of a net range. Convert to IPv4 if possible, otherwise return an ipv6

func ToMasks

func ToMasks(lancidrs []string) (masks []net.IPNet, err error)

converts a list of subnets' string to a list of net.IPNet.

Types

type IPFilter

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

func Default

func Default() *IPFilter

func New

func New(opts Options) *IPFilter

func (*IPFilter) AllowArea

func (f *IPFilter) AllowArea(code string)

func (*IPFilter) AllowIP

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

func (*IPFilter) Allowed

func (f *IPFilter) Allowed(ip string) bool

func (*IPFilter) AreaAllowed

func (f *IPFilter) AreaAllowed(code string) bool

func (*IPFilter) AreaBlocked

func (f *IPFilter) AreaBlocked(code string) bool

func (*IPFilter) BlockArea

func (f *IPFilter) BlockArea(code string)

func (*IPFilter) BlockIP

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

func (*IPFilter) Blocked

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

func (*IPFilter) NetAllowed

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

func (*IPFilter) NetBlocked

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

func (*IPFilter) RemoveCountry

func (f *IPFilter) RemoveCountry(code string)

func (*IPFilter) RemoveIP

func (f *IPFilter) RemoveIP(str string) bool

TODO

func (*IPFilter) ToggleDefault

func (f *IPFilter) ToggleDefault(allowed bool)

type Options

type Options struct {
	AllowedIPs []string
	BlockedIPs []string

	// explicity allowed country ISO codes
	AllowedAreas []string

	// explicity blocked country ISO codes
	BlockedAreas []string

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

Jump to

Keyboard shortcuts

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