net

package
v3.4.12 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const IPv4RE = "((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)[.]){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"

IPv4RE is a regular expression that will match an IPv4 address.

Variables

View Source
var ReservedCIDRs = []string{
	"192.168.0.0/16",
	"172.16.0.0/12",
	"10.0.0.0/8",
	"127.0.0.0/8",
	"224.0.0.0/4",
	"240.0.0.0/4",
	"100.64.0.0/10",
	"198.18.0.0/15",
	"169.254.0.0/16",
	"192.88.99.0/24",
	"192.0.0.0/24",
	"192.0.2.0/24",
	"192.94.77.0/24",
	"192.94.78.0/24",
	"192.52.193.0/24",
	"192.12.109.0/24",
	"192.31.196.0/24",
	"192.0.0.0/29",
}

ReservedCIDRs includes all the networks that are reserved for special use.

Functions

func AllHosts

func AllHosts(cidr *net.IPNet) []net.IP

AllHosts returns a slice containing all the IP addresses within the CIDR provided by the parameter. This implementation was obtained/modified from the following: https://gist.github.com/kotakanbe/d3059af990252ba89a82

func CIDRSubset

func CIDRSubset(cidr *net.IPNet, addr string, num int) []net.IP

CIDRSubset returns a subset of the IP addresses contained within the cidr parameter with num elements around the addr element.

func FirstLast

func FirstLast(cidr *net.IPNet) (net.IP, net.IP)

FirstLast return the first and last IP address of the provided CIDR/netblock.

func IPv6NibbleFormat

func IPv6NibbleFormat(ip string) string

IPv6NibbleFormat expects an IPv6 address in the ip parameter and returns the address in nibble format.

func IsIPv4

func IsIPv4(ip net.IP) bool

IsIPv4 returns true when the provided net.IP address is an IPv4 address.

func IsIPv6

func IsIPv6(ip net.IP) bool

IsIPv6 returns true when the provided net.IP address is an IPv6 address.

func Range2CIDR

func Range2CIDR(first, last net.IP) *net.IPNet

Range2CIDR turns an IP range into a CIDR.

func RangeHosts

func RangeHosts(start, end net.IP) []net.IP

RangeHosts returns all the IP addresses (inclusive) between the start and stop addresses provided by the parameters.

func ReverseIP

func ReverseIP(ip string) string

ReverseIP returns an IP address that is the ip parameter with the numbers reversed.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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