net

package
v0.0.0-...-2a31ebf Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 6 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.

View Source
const ReservedCIDRDescription = "Reserved Network Address Blocks"

ReservedCIDRDescription is the description used for reserved address ranges.

Variables

View Source
var LocalAddr net.Addr

LocalAddr is the global option for specifying the network interface.

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 DialContext

func DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext performs the dial using global variables (e.g. LocalAddr).

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 IPDec

func IPDec(ip net.IP)

IPDec decrements the IP address provided.

func IPInc

func IPInc(ip net.IP)

IPInc increments the IP address provided.

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 IsReservedAddress

func IsReservedAddress(addr string) (bool, string)

IsReservedAddress checks if the addr parameter is within one of the address ranges in the ReservedCIDRs slice.

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.

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