netmath

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 4 Imported by: 0

README

netmath

Helper functions and methods built on top of the net/netip standard Go libraries for sub/network based calculations

netmath documentation

Use netmath from the CLI: snet-cli

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Subnet

type Subnet struct {
	netip.Prefix
}

Network stuct based on netip.Prefix to add custom methods

func NewSubnet

func NewSubnet(p netip.Prefix) Subnet

Create a new Subnet from a netip.Prefix

func Parse

func Parse(addrStr string, maskStr string) (Subnet, error)

Parse an IP and Subnet Mask in the long <ip-address>, <subnet-mask> format

func ParseCIDR

func ParseCIDR(s string) (Subnet, error)

Parse an abbreviated IP and Subnet mask in the <ip-address>/<bits> format

func (Subnet) Broadcast

func (s Subnet) Broadcast() (netip.Addr, error)

Get the Broadcast address of the network ex. 192.168.20.15/23 -> 192.168.21.255

func (Subnet) Count

func (s Subnet) Count() (float64, error)

Count the number of total hosts in the subnet. (You can subtract two from the result for the usable hosts)

func (Subnet) ListAll

func (s Subnet) ListAll() []Subnet

List all of the neighboring subnets that use the same mask

func (Subnet) Mask

func (s Subnet) Mask() (netip.Addr, error)

Get the Network mask of the network

func (Subnet) Network

func (s Subnet) Network() (netip.Addr, error)

Get the Network address of the network ex. 192.168.20.15/23 -> 192.168.20.0

Jump to

Keyboard shortcuts

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