MakeIPMask

Description: Make an IP MaskSet that can then be passed into CheckIPMask and IPMaskToText, by returning text holding the encoded binary IP address and mask. Works for IPv4 and IPv6.
Returns: MaskSet value
Usage: Script Only.
Function Groups: Network and Workstation
Related to: CheckIPMask | IPMaskToText
Format: MakeIPMask((OldMaskSet, IPAddress [, Mask])
Parameters:  

OldMaskSet

Required. The result of previous calls to this method, or Invalid when starting afresh.

IPAddress

Required. This can be a single IP address, in which case the Mask parameter will be used if valid, OR an IP subnet address. IPv4 and IPv6 both have their subnet representations and either is acceptable here, as are IPv4-mapped IPv6 addresses.
Mask
Optional text. An optional IP mask, used as an alternative way of specifying a subnet range, in conjunction with a non-CIDR IPv4 or IPv6 second parameter.
Comments:

For advanced use only.

As a general process, use MakeIPMask to generate a MaskSet that can then be passed into CheckIPMask and IPMaskToText.

Use to generate a value that can then be fed into CheckIPMask to verify if an IP address is in the set of subnet ranges specified by the mask set built by this function.

In typical usage, OldMaskSet would initially be Invalid and a new MaskSet created as a result of the first call. Each time a successful call is made, the MaskSet grows by a fixed size (32 bytes), being 16 bytes of binary IP address 16 bytes of matching mask bits, held in a binary buffer.

IPv4 addresses/masks are expanded into IPv4-mapped IPv6 addresses to make them the same size.

No ordering or coalescence is done to reduce the mask to the minimum set needed.

An Invalid IPAddress parameter simply results in the first parameter (mask set) being returned unchanged. A bad one has no effect. This also means that this statement can be used to check the syntactic validity of an IP address or CIDR notation by passing Invalid for the OldMaskSet and checking the return value is valid.