iprange

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2020 License: GPL-3.0 Imports: 7 Imported by: 5

README

iprange

This package helps you to work with IP ranges.

IP range is a set of IP addresses. Both IPv4 and IPv6 are supported.

IP range interface:

type Range interface {
	Family() Family
	Contains(ip net.IP) bool
	Size() *big.Int
	fmt.Stringer
}

Supported formats

  • IPv4 address (192.0.2.1)
  • IPv4 range (192.0.2.0-192.0.2.10)
  • IPv4 CIDR (192.0.2.0/24)
  • IPv4 subnet mask (192.0.2.0/255.255.255.0)
  • IPv6 address (2001:db8::1)
  • IPv6 range (2001:db8::-2001:db8::10)
  • IPv6 CIDR (2001:db8::/64)

IP range doesn't contain network and broadcast IP addresses if the format is IPv4 CIDR, IPv4 subnet mask or IPv6 CIDR.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Family

type Family uint8

Family represents IP Range address-family.

const (
	// V4Family is IPv4 address-family.
	V4Family Family = iota
	// V6Family is IPv6 address-family.
	V6Family
)

type Pool

type Pool []Range

Pool is a collection of IP Ranges.

func (Pool) Contains

func (p Pool) Contains(ip net.IP) bool

Contains reports whether the pool includes IP.

func (Pool) Size

func (p Pool) Size() *big.Int

Size reports the number of IP addresses in the pool.

func (Pool) String

func (p Pool) String() string

String returns the string form of the pool.

type Range

type Range interface {
	Family() Family
	Contains(ip net.IP) bool
	Size() *big.Int
	fmt.Stringer
}

Range represents an IP range.

func New

func New(start, end net.IP) Range

New returns new IP Range. If it is not a valid range (start and end IPs have different address-families, or start > end), New returns nil.

func ParseRange

func ParseRange(s string) (Range, error)

ParseRange parses s as an IP Range, returning the result and an error if any. The string s can be in IPv4 address ("192.0.2.1"), IPv4 range ("192.0.2.0-192.0.2.10") IPv4 CIDR ("192.0.2.0/24"), IPv4 subnet mask ("192.0.2.0/255.255.255.0"), IPv6 address ("2001:db8::1"), IPv6 range ("2001:db8::-2001:db8::10"), or IPv6 CIDR ("2001:db8::/64") form. IPv4 CIDR, IPv4 subnet mask and IPv6 CIDR ranges don't include network and broadcast addresses.

func ParseRanges

func ParseRanges(s string) ([]Range, error)

ParseRanges parses s as a space separated list of IP Ranges, returning the result and an error if any. IP Range can be in IPv4 address ("192.0.2.1"), IPv4 range ("192.0.2.0-192.0.2.10") IPv4 CIDR ("192.0.2.0/24"), IPv4 subnet mask ("192.0.2.0/255.255.255.0"), IPv6 address ("2001:db8::1"), IPv6 range ("2001:db8::-2001:db8::10"), or IPv6 CIDR ("2001:db8::/64") form. IPv4 CIDR, IPv4 subnet mask and IPv6 CIDR ranges don't include network and broadcast addresses.

Jump to

Keyboard shortcuts

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