ipnetgen

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 2 Imported by: 17

README

ipnetgen

-- import "github.com/korylprince/ipnetgen"

Package ipnetgen provides a way to iterate over the addresses in a subnet:

gen, err := New("192.168.100.0/24")
if err != nil {
	//do something with err
}
for ip := gen.Next(); ip != nil; ip = gen.Next() {
	//do something with ip
}

ipnetgen works on net.IPs, meaning it supports both IPv4 and IPv6 addresses.

Usage

func Increment
func Increment(ip net.IP)

Increment increments the given net.IP by one bit. Incrementing the last IP in an IP space (IPv4, IPV6) is undefined.

type IPNetGenerator
type IPNetGenerator struct {
	*net.IPNet
}

IPNetGenerator is a net.IPnet wrapper that you can iterate over

func New
func New(cidr string) (*IPNetGenerator, error)

New creates a new IPNetGenerator from a CIDR string, or an error if the CIDR is invalid.

func NewFromIPNet
func NewFromIPNet(ipNet *net.IPNet) *IPNetGenerator

NewFromIPNet creates a new IPNetGenerator from a *net.IPNet

func (*IPNetGenerator) Next
func (g *IPNetGenerator) Next() net.IP

Next returns the next net.IP in the subnet

Documentation

Overview

Package ipnetgen provides a way to iterate over the addresses in a subnet:

gen, err := New("192.168.100.0/24")
if err != nil {
	//do something with err
}
for ip := gen.Next(); ip != nil; ip = gen.Next() {
	//do something with ip
}

ipnetgen works on net.IPs, meaning it supports both IPv4 and IPv6 addresses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Increment

func Increment(ip net.IP)

Increment increments the given net.IP by one bit. Incrementing the last IP in an IP space (IPv4, IPV6) is undefined.

Types

type IPNetGenerator

type IPNetGenerator struct {
	*net.IPNet
	// contains filtered or unexported fields
}

IPNetGenerator is a net.IPnet wrapper that you can iterate over

func New

func New(cidr string) (*IPNetGenerator, error)

New creates a new IPNetGenerator from a CIDR string, or an error if the CIDR is invalid.

func NewFromIPNet

func NewFromIPNet(ipNet *net.IPNet) *IPNetGenerator

NewFromIPNet creates a new IPNetGenerator from a *net.IPNet

func (*IPNetGenerator) Next

func (g *IPNetGenerator) Next() net.IP

Next returns the next net.IP in the subnet

Jump to

Keyboard shortcuts

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