Help us shape the future of Go! Take the 2026 Go Developer Survey

iprange

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2018 License: MIT Imports: 11 Imported by: 190

README

iprange

GoDoc license Build Status

iprange is a library you can use to parse IPv4 addresses from a string in the nmap format.

It takes a string, and returns a list of Min-Max pairs, which can then be expanded and normalized automatically by the package.

Supported Formats

iprange supports the following formats:

  • 10.0.0.1
  • 10.0.0.0/24
  • 10.0.0.*
  • 10.0.0.1-10
  • 10.0.0.1, 10.0.0.5-10, 192.168.1.*, 192.168.10.0/24

Usage

package main

import (
	"log"

	"github.com/malfunkt/iprange"
)

func main() {
	list, err := iprange.ParseList("10.0.0.1, 10.0.0.5-10, 192.168.1.*, 192.168.10.0/24")
	if err != nil {
		log.Printf("error: %s", err)
	}
	log.Printf("%+v", list)

	rng := list.Expand()
	log.Printf("%s", rng)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressRange

type AddressRange struct {
	Min net.IP
	Max net.IP
}

func Parse

func Parse(in string) (*AddressRange, error)

Parse takes a single target specification and returns a range. It effectively calls ParseList and returns the first result

func (*AddressRange) Expand

func (r *AddressRange) Expand() []net.IP

Expand expands an address with a mask taken from a stream

type AddressRangeList

type AddressRangeList []AddressRange

func ParseList

func ParseList(in string) (AddressRangeList, error)

ParseList takes a list of target specifications and returns a list of ranges, even if the list contains a single element.

func (AddressRangeList) Expand

func (l AddressRangeList) Expand() []net.IP

Expand expands and normalizes a set of parsed target specifications

Jump to

Keyboard shortcuts

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