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: 89 modules, 190 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址