Cidr
net_cidr_to_mask¶
Convert a CIDR prefix length to a dotted-decimal subnet mask. Accepts the prefix with or without a leading slash (e.g. /24 or 24).
Example¶
net_cidr_to_mask 24 # => 255.255.255.0
net_cidr_to_mask /16 # => 255.255.0.0
Arguments¶
- $1 (string): CIDR prefix length, e.g. 24 or /24
Exit codes¶
- 0: Success
- 1: No valid argument supplied
Output on stdout¶
- The subnet mask in dotted-decimal notation
net_cidr_table¶
Print a table of all CIDR prefix lengths and their corresponding subnet masks, from /32 down to /0.
Exit codes¶
- 0: Always
Output on stdout¶
- Formatted table of prefix lengths and subnet masks
net_mask_to_cidr¶
Convert a dotted-decimal subnet mask to a CIDR prefix length. The mask must be a valid contiguous subnet mask (e.g. 255.255.255.0). Non-contiguous masks (e.g. 255.255.1.0) are rejected.
Example¶
net_mask_to_cidr 255.255.255.0 # => 24
net_mask_to_cidr 255.255.0.0 # => 16
Arguments¶
- $1 (string): Dotted-decimal subnet mask, e.g. 255.255.255.0
Exit codes¶
- 0: Success
- 1: Invalid or non-contiguous mask supplied
Output on stdout¶
- The CIDR prefix length as a plain integer
net_subnet_size¶
Print the total number of addresses in a subnet for a given CIDR prefix length. Accepts the prefix with or without a leading slash. Note: /32 = 1 address (host route); /31 = 2 addresses (point-to-point, RFC 3021); all others include network and broadcast addresses in the count.
Example¶
net_subnet_size 24 # => 256
net_subnet_size /16 # => 65536
Arguments¶
- $1 (string): CIDR prefix length, e.g. 24 or /24
Exit codes¶
- 0: Success
- 1: No valid argument supplied
Output on stdout¶
- Total address count as a plain integer
net_network_address¶
Derive the network address from an IP address and CIDR prefix. Accepts combined notation (ip/prefix) or two separate arguments.
Example¶
net_network_address 192.168.1.50/24 # => 192.168.1.0
net_network_address 10.0.3.7 8 # => 10.0.0.0
Arguments¶
- $1 (string): IP address with optional prefix (e.g. 192.168.1.50/24), or bare IP
- $2 (int): CIDR prefix length when not embedded in $1 (e.g. 24)
Exit codes¶
- 0: Success
- 1: Missing argument
Output on stdout¶
- Network address in dotted-decimal notation
net_broadcast_address¶
Derive the broadcast address from an IP address and CIDR prefix. Accepts combined notation (ip/prefix) or two separate arguments.
Example¶
net_broadcast_address 192.168.1.50/24 # => 192.168.1.255
net_broadcast_address 10.0.3.7 8 # => 10.255.255.255
Arguments¶
- $1 (string): IP address with optional prefix (e.g. 192.168.1.50/24), or bare IP
- $2 (int): CIDR prefix length when not embedded in $1 (e.g. 24)
Exit codes¶
- 0: Success
- 1: Missing argument
Output on stdout¶
- Broadcast address in dotted-decimal notation