Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IPv4 ¶
func NewIPv4 ¶
NewIPv4 creates a new IPv4 instance.
Parameters:
a, b, c, d: The four octets of the IPv4 address. maskBits: The number of bits in the subnet mask.
Returns:
*IPv4: A new IPv4 instance.
func NewIPv4FromString ¶
NewIPv4FromString creates a new IPv4 instance from a string.
Parameters:
s: The string representation of the IPv4 address.
Returns:
*IPv4: A new IPv4 instance.
func (*IPv4) CIDRAddress ¶
CIDRAddress returns the CIDR address of the IPv4 address.
Returns:
string: The CIDR address of the IPv4 address.
func (*IPv4) CIDRMask ¶
CIDRMask returns the CIDR mask of the IPv4 address.
Returns:
string: The CIDR mask of the IPv4 address.
func (*IPv4) ComputeMask ¶
ComputeMask calculates the network address by applying the subnet mask to the IPv4 address. It returns a new IPv4 instance representing the network address.
The function first converts the IPv4 address to a 32-bit unsigned integer. Then, it creates a subnet mask by shifting the bits of 0xFFFFFFFF to the left by (32 - MaskBits) positions. The subnet mask is then applied to the 32-bit representation of the IPv4 address using a bitwise AND operation.
Finally, the resulting network address is split back into its four octets (A, B, C, D) and a new IPv4 instance is created and returned with the same MaskBits value.
Example:
ip := NewIPv4(192, 168, 1, 17, 24) networkAddress := ip.ComputeMask() fmt.Println(networkAddress.String()) // Output: 192.168.1.0/24
Returns:
*IPv4: A new IPv4 instance representing the network address.
func (*IPv4) IsInRange ¶
IsInRange checks if the IPv4 address is within the range of two other IPv4 addresses.
Parameters:
start: The start of the range. end: The end of the range.
Returns:
bool: True if the IPv4 address is within the range, false otherwise.
func (*IPv4) IsInSubnet ¶
IsInSubnet checks if the IPv4 address is within the subnet of another IPv4 address.
Parameters:
subnet: The subnet to check against.
Returns:
bool: True if the IPv4 address is within the subnet, false otherwise.
type IPv4Range ¶
type IPv6 ¶
type IPv6 struct {
A, B, C, D, E, F, G, H uint16
}
func NewIPv6 ¶
NewIPv6 creates a new IPv6 instance.
Parameters:
a, b, c, d, e, f, g, h: The eight segments of the IPv6 address.
Returns:
*IPv6: A new IPv6 instance.
func NewIPv6FromString ¶
NewIPv6FromString creates a new IPv6 instance from a string.
Parameters:
s: The string representation of the IPv6 address.
Returns:
*IPv6: A new IPv6 instance.
func (*IPv6) IsInRange ¶
IsInRange checks if the IPv6 address is within the range of two other IPv6 addresses.
Parameters:
start: The start of the range. end: The end of the range.
Returns:
bool: True if the IPv6 address is within the range, false otherwise.
func (*IPv6) IsInSubnet ¶
IsInSubnet checks if the IPv6 address is within the subnet of another IPv6 address.
Parameters:
subnet: The subnet to check against.
Returns:
bool: True if the IPv6 address is within the subnet, false otherwise.
type IPv6Range ¶
IPv6Range represents a range of IPv6 addresses.
type TCPPortRange ¶
func NewTCPPortRange ¶
func NewTCPPortRange(start, end uint16) *TCPPortRange
NewTCPPortRange creates a new TCP port range instance.
Parameters:
start: The start port number. end: The end port number.
Returns:
*TCPPortRange: A new TCP port range instance.
func NewTCPPortRangeFromString ¶
func NewTCPPortRangeFromString(s string) (*TCPPortRange, error)
NewTCPPortRangeFromString creates a new TCP port range instance from a string.
Parameters:
s: The string representation of the TCP port range.
Returns:
*TCPPortRange: A new TCP port range instance.
func (*TCPPortRange) String ¶
func (t *TCPPortRange) String() string
String returns the string representation of the TCP port range.
Returns:
string: The string representation of the TCP port range.