Documentation ¶
Index ¶
- Variables
- func ConvertToIP[T IPTypes](ip T) net.IP
- func GetList(n net.IPNet) (net.IP, net.IP, <-chan net.IP, error)
- func GetList4(n net.IPNet) (net.IP, net.IP, <-chan net.IP, error)
- func GetList6(n net.IPNet) (net.IP, net.IP, <-chan net.IP, error)
- func GetPublic() net.IP
- func GetPublic4() net.IP
- func GetPublic6() net.IP
- func GetRandom() net.IP
- func GetRandom4() net.IP
- func GetRandom6() net.IP
- func Increase(ip net.IP)
- func IsLAN(ip net.IP) bool
- func IsReserved(ip net.IP) bool
- func IsReserved4(ip net.IP) bool
- func IsReserved6(ip net.IP) bool
- func IsValid[T IPTypes](ip T) bool
- func IsValid4[T IPTypes](ip T) bool
- func IsValid6[T IPTypes](ip T) booldeprecated
- type IPTypes
Constants ¶
This section is empty.
Variables ¶
var ( // /32 network mask Mask32 = net.IPMask{0xff, 0xff, 0xff, 0xff} // /31 network mask Mask31 = net.IPMask{0xff, 0xff, 0xff, 0xfe} )
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} )
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
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 ¶
Convert any IPType to net.IP. If not an IP, returns nil.
func GetList ¶
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 ¶
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 ¶
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 ¶
GetPublic is return a *non reserved* IP address. The version of the IP protocol is random.
func GetRandom ¶
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 ¶
GetRandom4 is return a random IPv4 address. The returned IP *can be* a reserved address.
func GetRandom6 ¶
GetRandom6 is return a random IPv6 address. The returned IP *can be* a reserved address.
func IsLAN ¶
IsLAN checks whether the given IP is in your LAN's subnet by iteraet over the interfaces. It will panics on error.
func IsReserved ¶
IsReservedIP checks whether ip is in the reserved address range.
func IsReserved4 ¶
IsReserved4 checks if the given IPv4 address is reserved.
func IsReserved6 ¶
IsReserved6 checks if the given IPv6 address is reserved.