ip

package
v0.0.0-...-eb2fa4d Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// /32 network mask
	Mask32 = net.IPMask{0xff, 0xff, 0xff, 0xff}
	// /31 network mask
	Mask31 = net.IPMask{0xff, 0xff, 0xff, 0xfe}
)
View Source
var (
	// /128 network mask
	Mask128 = net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
	// /127 network mask
	Mask127 = net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe}
)
View Source
var ReservedIPv4 = []net.IPNet{
	{IP: net.IPv4(0, 0, 0, 0), Mask: net.IPv4Mask(255, 0, 0, 0)},
	{IP: net.IPv4(10, 0, 0, 0), Mask: net.IPv4Mask(255, 0, 0, 0)},
	{IP: net.IPv4(100, 64, 0, 0), Mask: net.IPv4Mask(255, 192, 0, 0)},
	{IP: net.IPv4(127, 0, 0, 0), Mask: net.IPv4Mask(255, 0, 0, 0)},
	{IP: net.IPv4(169, 254, 0, 0), Mask: net.IPv4Mask(255, 255, 0, 0)},
	{IP: net.IPv4(172, 16, 0, 0), Mask: net.IPv4Mask(255, 240, 0, 0)},
	{IP: net.IPv4(192, 0, 0, 0), Mask: net.IPv4Mask(255, 255, 255, 0)},
	{IP: net.IPv4(192, 0, 2, 0), Mask: net.IPv4Mask(255, 255, 255, 0)},
	{IP: net.IPv4(192, 88, 99, 0), Mask: net.IPv4Mask(255, 255, 255, 0)},
	{IP: net.IPv4(192, 168, 0, 0), Mask: net.IPv4Mask(255, 255, 0, 0)},
	{IP: net.IPv4(198, 18, 0, 0), Mask: net.IPv4Mask(255, 254, 0, 0)},
	{IP: net.IPv4(198, 51, 100, 0), Mask: net.IPv4Mask(255, 255, 255, 0)},
	{IP: net.IPv4(203, 0, 113, 0), Mask: net.IPv4Mask(255, 255, 255, 0)},
	{IP: net.IPv4(224, 0, 0, 0), Mask: net.IPv4Mask(240, 0, 0, 0)},
	{IP: net.IPv4(233, 252, 0, 0), Mask: net.IPv4Mask(255, 255, 255, 0)},
	{IP: net.IPv4(240, 0, 0, 0), Mask: net.IPv4Mask(240, 0, 0, 0)},
	{IP: net.IPv4(255, 255, 255, 255), Mask: net.IPv4Mask(255, 255, 255, 255)},
}

ReservedIPv4 is a collection of reserved IPv4 addresses. Source: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml

View Source
var ReservedIPv6 = []net.IPNet{
	{IP: net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}},
	{IP: net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, Mask: net.IPMask{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}},
	{IP: net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0}},
	{IP: net.IP{0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0}},
	{IP: net.IP{0, 100, 255, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0}},
	{IP: net.IP{0, 100, 255, 155, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
	{IP: net.IP{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0}},
	{IP: net.IP{32, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
	{IP: net.IP{32, 1, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
	{IP: net.IP{32, 1, 13, 184, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
	{IP: net.IP{32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
	{IP: net.IP{252, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
	{IP: net.IP{254, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
	{IP: net.IP{255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Mask: net.IPMask{255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
}

ReservedIPv6 is a collection of reserved IPv6 addresses.

Functions

func ConvertToIP

func ConvertToIP[T IPTypes](ip T) net.IP

Convert any IPType to net.IP. If not an IP, returns nil.

func GetList

func GetList(n net.IPNet) (net.IP, net.IP, <-chan net.IP, error)

GetList creates a list of address on the given IPNet. Returns the first (identification address), the last (broadcast address) and a channel of usable IP addresses. If the mask is /32 or /128, the last and the usable channel is nil. If the mask is /31 or /127, the usable channel is nil.

func GetList4

func GetList4(n net.IPNet) (net.IP, net.IP, <-chan net.IP, error)

GetList4 creates a list of IPv4 address on the given IPNet. Returns the first (identification address), the last (broadcast address) and a channel of usable IP addresses. If the mask is /32 the last and the usable channel is nil. If the mask is /31 the usable channel is nil.

func GetList6

func GetList6(n net.IPNet) (net.IP, net.IP, <-chan net.IP, error)

GetList6 creates a list of IPv6 address on the given IPNet. Returns the first (identification address), the last (broadcast address) and a channel of usable IP addresses. If the mask is /128 the last and the usable channel is nil. If the mask is /127 the usable channel is nil.

func GetPublic

func GetPublic() net.IP

GetPublic is return a *non reserved* IP address. The version of the IP protocol is random.

func GetPublic4

func GetPublic4() net.IP

GetPublic4 is return a *non reserved* IPv4 address.

func GetPublic6

func GetPublic6() net.IP

GetPublic6 is return a *non reserved* IPv6 address.

func GetRandom

func GetRandom() net.IP

GetRandom is return a random IP address. The returned IP *can be* a reserved address. The version of the IP protocol is random.

func GetRandom4

func GetRandom4() net.IP

GetRandom4 is return a random IPv4 address. The returned IP *can be* a reserved address.

func GetRandom6

func GetRandom6() net.IP

GetRandom6 is return a random IPv6 address. The returned IP *can be* a reserved address.

func Increase

func Increase(ip net.IP)

Increase ip to the next address.

func IsLAN

func IsLAN(ip net.IP) bool

IsLAN checks whether the given IP is in your LAN's subnet by iteraet over the interfaces. It will panics on error.

func IsReserved

func IsReserved(ip net.IP) bool

IsReservedIP checks whether ip is in the reserved address range.

func IsReserved4

func IsReserved4(ip net.IP) bool

IsReserved4 checks if the given IPv4 address is reserved.

func IsReserved6

func IsReserved6(ip net.IP) bool

IsReserved6 checks if the given IPv6 address is reserved.

func IsValid

func IsValid[T IPTypes](ip T) bool

IsValidIP checks whether ip is valid IP address.

func IsValid4

func IsValid4[T IPTypes](ip T) bool

IsValid4 checks whether ip is valid IPv4 address.

func IsValid6 deprecated

func IsValid6[T IPTypes](ip T) bool

IsValid6 checks whether ip is valid IPv6 address. This function is a wrapper for github.com/elmasy-com/elnet/validator.IPv6

Deprecated: Use github.com/elmasy-com/elnet/validator instead.

Types

type IPTypes

type IPTypes interface {
	net.IP | *net.IP | net.IPNet | *net.IPNet | net.IPAddr | *net.IPAddr | net.TCPAddr | *net.TCPAddr | net.UDPAddr | *net.UDPAddr | string | *string
}

Jump to

Keyboard shortcuts

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