Parses an IP address range in CIDR notation and returns an object containing various properties of the address range.
Parameter | Required | Type | Description |
---|---|---|---|
network |
Yes | string |
String containing an IP address range to convert in CIDR format |
Splits the specified IP address range in CIDR notation into subnets with a new CIDR value and returns the IP address range of the subnet with the specified index.
Parameter | Required | Type | Description |
---|---|---|---|
network |
Yes | string |
String containing an IP address range to convert in CIDR format |
cidr |
Yes | int |
An integer representing the CIDR to be used to subnet |
subnetIndex |
Yes | int |
Index of the desired subnet IP address range to return |
Calculates the IP address of the host with the specified index on the specified IP address range in CIDR notation. Only considers usable IP addresses.
Parameter | Required | Type | Description |
---|---|---|---|
network |
Yes | string |
String containing an ip network to convert (must be correct networking format) |
hostIndex |
Yes | int |
The index of the host IP address to return. |
/*
----- IPv4 -----
*/
// parse IPv4 CIDR string
output v4info object = parseCidr('10.144.0.0/20')
/*
Returns:
{
network: '10.144.0.0'
netmask: '255.255.240.0'
broadcast: '10.144.15.255'
firstUsable: '10.144.0.1'
lastUsable: '10.144.15.254'
cidr: 20
}
*/
// calculate the first five /24 subnet ranges from the specified /20
output v4subnets array = [for i in range(0, 5): cidrSubnet('10.144.0.0/20', 24, i)]
/*
Returns:
[
'10.144.0.0/24'
'10.144.1.0/24'
'10.144.2.0/24'
'10.144.3.0/24'
'10.144.4.0/24'
]
*/
// calculate the first five usable host IP addresses from the specified /24
output v4hosts array = [for i in range(0, 5): cidrHost('10.144.3.0/24', i)]
/*
Returns:
[
'10.144.3.1'
'10.144.3.2'
'10.144.3.3'
'10.144.3.4'
'10.144.3.5'
]
*/
/*
----- IPv6 -----
*/
// parse IPv6 CIDR string
output v6info object = parseCidr('fdad:3236:5555::/48')
/*
Returns:
{
network: 'fdad:3236:5555::'
netmask: 'ffff:ffff:ffff::'
firstUsable: 'fdad:3236:5555::'
lastUsable: 'fdad:3236:5555:ffff:ffff:ffff:ffff:ffff'
cidr: 48
}
*/
// calculate the first five /52 subnet ranges from the specified /48
output v6subnets array = [for i in range(0, 5): cidrSubnet('fdad:3236:5555::/48', 52, i)]
/*
Returns:
[
'fdad:3236:5555::/52'
'fdad:3236:5555:1000::/52'
'fdad:3236:5555:2000::/52'
'fdad:3236:5555:3000::/52'
'fdad:3236:5555:4000::/52'
]
*/
// calculate the first five usable host IP addresses from the specified /52
output v6hosts array = [for i in range(0, 5): cidrHost('fdad:3236:5555:3000::/52', i)]
/*
Returns:
[
'fdad:3236:5555:3000::1'
'fdad:3236:5555:3000::2'
'fdad:3236:5555:3000::3'
'fdad:3236:5555:3000::4'
'fdad:3236:5555:3000::5'
]
*/
I would offer that forcing the function to skip the first 3 would limit it's application to non-Azure CIDR values, such as when calculating first/last usable for a CIDR from an external network to configure firewall rules. Those external networks don't necessarily skip the first 3 like Azure does.
If we need to skip the first few for an Azure CIDR, we should be able to just start the range at something higher than
0
, correct?