Functions for working with IPv4 and IPv6 addresses
IPv4CIDRToRange
Introduced in: v20.1
Takes an IPv4 address with its Classless Inter-Domain Routing (CIDR) prefix length and returns the subnet's address range as a tuple of two IPv4 values: the first and last addresses in that subnet.
For the IPv6 version see IPv6CIDRToRange
.
Syntax
Arguments
Returned value
Returns a tuple with two IPv4 addresses representing the subnet range. Tuple(IPv4, IPv4)
Examples
Usage example
IPv4NumToString
Introduced in: v1.1
Converts a 32-bit integer to its IPv4 address string representation in dotted decimal notation (A.B.C.D format). Interprets the input using big-endian byte ordering.
Syntax
Arguments
num
— IPv4 address as UInt32 number.UInt32
Returned value
Returns a number representing the MAC address, or 0
if the format is invalid. String
Examples
Usage example
IPv4NumToStringClassC
Introduced in: v1.1
Converts a 32-bit integer to its IPv4 address string representation in dotted decimal notation (A.B.C.D format),
similar to IPv4NumToString
but using xxx
instead of the last octet.
Syntax
Arguments
num
— IPv4 address as UInt32 number.UInt32
Returned value
Returns the IPv4 address string with xxx replacing the last octet. String
Examples
Basic example with aggregation
IPv4StringToNum
Introduced in: v1.1
Converts an IPv4 address string in dotted decimal notation (A.B.C.D format) to its corresponding 32-bit integer representation. (The reverse of IPv4NumToString
).
If the IPv4 address has an invalid format, an exception is thrown.
Syntax
Arguments
string
— IPv4 address string.String
Returned value
Returns theIPv4 address. UInt32
Examples
Usage example
IPv4StringToNumOrDefault
Introduced in: v22.3
Converts an IPv4 address string in dotted decimal notation (A.B.C.D format) to its corresponding 32-bit integer representation but if the IPv4 address has an invalid format, it returns 0
.
Syntax
Arguments
string
— IPv4 address string.String
Returned value
Returns the IPv4 address, or 0
if invalid. UInt32
Examples
Example with an invalid address
IPv4StringToNumOrNull
Introduced in: v22.3
Converts a 32-bit integer to its IPv4 address string representation in dotted decimal notation (A.B.C.D format) but if the IPv4 address has an invalid format, it returns NULL
.
Syntax
Arguments
string
— IPv4 address string.String
Returned value
Returns the IPv4 address, or NULL
if invalid. Nullable(UInt32)
Examples
Example with an invalid address
IPv4ToIPv6
Introduced in: v1.1
Interprets a (big endian) 32-bit number as an IPv4 address, which is then interpreted as the corresponding IPv6 address in FixedString(16)
format.
Syntax
Arguments
x
— IPv4 address.UInt32
Returned value
Returns an IPv6 address in binary format. FixedString(16)
Examples
Usage example
IPv6CIDRToRange
Introduced in: v20.1
Takes an IPv6 address with its Classless Inter-Domain Routing (CIDR) prefix length and returns the subnet's address range as a tuple of two IPv6 values: the lowest and highest addresses in that subnet.
For the IPv4 version see IPv4CIDRToRange
.
Syntax
Arguments
Returned value
Returns a tuple with two IPv6 addresses representing the subnet range. Tuple(IPv6, IPv6)
Examples
Usage example
IPv6NumToString
Introduced in: v1.1
Converts an IPv6 address from binary format (FixedString(16)) to its standard text representation.
IPv4-mapped IPv6 addresses are displayed in the format ::ffff:111.222.33.44
.
Syntax
Arguments
x
— IPv6 address in binary format.FixedString(16)
orIPv6
Returned value
Returns the IPv6 address string in text format. String
Examples
Usage example
IPv6 with hits analysis
IPv6 mapped IPv4 addresses
IPv6StringToNum
Introduced in: v1.1
Converts an IPv6 address from its standard text representation to binary format (FixedString(16)
).
Accepts IPv4-mapped IPv6 addresses in the format ::ffff:111.222.33.44.
.
If the IPv6 address has an invalid format, an exception is thrown.
If the input string contains a valid IPv4 address, returns its IPv6 equivalent. HEX can be uppercase or lowercase.
Syntax
Arguments
string
— IPv6 address string.String
Returned value
Returns theIPv6 address in binary format. FixedString(16)
Examples
Basic example
IPv6StringToNumOrDefault
Introduced in: v22.3
Converts an IPv6 address from its standard text representation to binary format (FixedString(16)
).
Accepts IPv4-mapped IPv6 addresses in the format ::ffff:111.222.33.44.
.
If the IPv6 address has an invalid format, it returns the default value ::
.
Syntax
Arguments
string
— IPv6 address string.String
Returned value
IPv6 address in binary format, or zero-filled FixedString(16) if invalid. FixedString(16)
Examples
Basic example with invalid address
IPv6StringToNumOrNull
Introduced in: v22.3
Converts an IPv6 address from its standard text representation to binary format (FixedString(16)
).
Accepts IPv4-mapped IPv6 addresses in the format ::ffff:111.222.33.44.
.
If the IPv6 address has an invalid format, it returns NULL
.
Syntax
Arguments
string
— IPv6 address string.String
Returned value
Returns IPv6 address in binary format, or NULL
if invalid. Nullable(FixedString(16))
Examples
Basic example with invalid address
cutIPv6
Introduced in: v1.1
Accepts a FixedString(16)
value containing the IPv6 address in binary format.
Returns a string containing the address of the specified number of bytes removed in text format.
Syntax
Arguments
x
— IPv6 address in binary format.FixedString(16)
orIPv6
bytesToCutForIPv6
— Number of bytes to cut for IPv6.UInt8
bytesToCutForIPv4
— Number of bytes to cut for IPv4.UInt8
Returned value
Returns a string containing the IPv6 address in text format with specified bytes removed. String
Examples
Usage example
isIPAddressInRange
Introduced in: v21.4
Determines if an IP address is contained in a network represented in the Classless Inter-Domain Routing (CIDR) notation.
This function accepts both IPv4 and IPv6 addresses (and networks) represented as strings. It returns 0
if the IP version of the address and the CIDR don't match.
Syntax
Arguments
Returned value
Returns 1
if the IP version of the address and the CIDR match, otherwise 0
. UInt8
Examples
IPv4 address in range
IPv4 address not in range
IPv6 address not in range
isIPv4String
Introduced in: v21.1
Determines whether the input string is an IPv4 address or not.
For the IPv6 version see isIPv6String
.
Syntax
Arguments
string
— IP address string to check.String
Returned value
Returns 1
if string
is IPv4 address, otherwise 0
. UInt8
Examples
Usage example
isIPv6String
Introduced in: v21.1
Determines whether the input string is an IPv6 address or not.
For the IPv4 version see isIPv4String
.
Syntax
Arguments
string
— IP address string to check.String
Returned value
Returns 1
if string
is IPv6 address, otherwise 0
. UInt8
Examples
Usage example
toIPv4
Introduced in: v20.1
Converts a string or a UInt32 form of IPv4 address to type IPv4.
It is similar to IPv4StringToNum
and IPv4NumToString
functions but it supports both string and unsigned integer data types as input arguments.
Syntax
Arguments
x
— An IPv4 addressString
orUInt8/16/32
Returned value
Returns an IPv4 address. IPv4
Examples
Usage example
Comparison with IPv4StringToNum and IPv4NumToString functions.
Conversion from an integer
toIPv4OrDefault
Introduced in: v22.3
Converts a string or a UInt32 form of an IPv4 address to IPv4
type.
If the IPv4 address has an invalid format, it returns 0.0.0.0
(0 IPv4), or the provided IPv4 default.
Syntax
Arguments
string
— IP address string to convert.String
default
— Optional. The value to return if string is an invalid IPv4 address.IPv4
Returned value
Returns a string converted to the current IPv4 address, or the default value if conversion fails. IPv4
Examples
Valid and invalid IPv4 strings
toIPv4OrNull
Introduced in: v22.3
Converts an input value to a value of type IPv4
but returns NULL
in case of an error.
Like toIPv4
but returns NULL
instead of throwing an exception on conversion errors.
Supported arguments:
- String representations of IPv4 addresses in dotted decimal notation.
- Integer representations of IPv4 addresses.
Unsupported arguments (return NULL
):
- Invalid IP address formats.
- IPv6 addresses.
- Out-of-range values.
- Malformed addresses.
Syntax
Arguments
Returned value
Returns an IPv4 address if successful, otherwise NULL
. IPv4
or NULL
Examples
Usage example
toIPv4OrZero
Introduced in: v23.1
Converts an input value to a value of type IPv4 but returns zero IPv4 address in case of an error.
Like toIPv4
but returns zero IPv4 address (0.0.0.0
) instead of throwing an exception on conversion errors.
Supported arguments:
- String representations of IPv4 addresses in dotted decimal notation.
- Integer representations of IPv4 addresses.
Unsupported arguments (return zero IPv4):
- Invalid IP address formats.
- IPv6 addresses.
- Out-of-range values.
Syntax
Arguments
Returned value
Returns an IPv4 address if successful, otherwise zero IPv4 address (0.0.0.0
). IPv4
Examples
Usage example
toIPv6
Introduced in: v20.1
onverts a string or a UInt128
form of IPv6 address to IPv6
type.
For strings, if the IPv6 address has an invalid format, returns an empty value.
Similar to IPv6StringToNum
and IPv6NumToString
functions, which convert IPv6 address to and from binary format (i.e. FixedString(16)
).
If the input string contains a valid IPv4 address, then the IPv6 equivalent of the IPv4 address is returned.
Syntax
Arguments
Returned value
Returns an IPv6 address. IPv6
Examples
Usage example
IPv4-to-IPv6 mapping
toIPv6OrDefault
Introduced in: v22.3
Converts a string or a UInt128 form of IPv6 address to IPv6
type.
If the IPv6 address has an invalid format, it returns ::
(0 IPv6) or the provided IPv6 default.
Syntax
Arguments
string
— IP address string to convert. -default
— Optional. The value to return if string has an invalid format.
Returned value
Returns the IPv6 address, otherwise ::
or the provided optional default if argument string
has an invalid format. IPv6
Examples
Valid and invalid IPv6 strings
toIPv6OrNull
Introduced in: v22.3
Converts an input value to a value of type IPv6
but returns NULL
in case of an error.
Like toIPv6
but returns NULL
instead of throwing an exception on conversion errors.
Supported arguments:
- String representations of IPv6 addresses in standard notation.
- String representations of IPv4 addresses (converted to IPv4-mapped IPv6).
- Binary representations of IPv6 addresses.
Unsupported arguments (return NULL
):
- Invalid IP address formats.
- Malformed IPv6 addresses.
- Out-of-range values.
- Invalid notation.
Syntax
Arguments
x
— A string representation of an IPv6 or IPv4 address.String
Returned value
Returns an IPv6 address if successful, otherwise NULL
. IPv6
or NULL
Examples
Usage example
toIPv6OrZero
Introduced in: v23.1
Converts an input value to a value of type IPv6 but returns zero IPv6 address in case of an error.
Like toIPv6
but returns zero IPv6 address (::
) instead of throwing an exception on conversion errors.
Supported arguments:
- String representations of IPv6 addresses in standard notation.
- String representations of IPv4 addresses (converted to IPv4-mapped IPv6).
- Binary representations of IPv6 addresses.
Unsupported arguments (return zero IPv6):
- Invalid IP address formats.
- Malformed IPv6 addresses.
- Out-of-range values.
Syntax
Arguments
x
— A string representation of an IPv6 or IPv4 address.String
Returned value
Returns an IPv6 address if successful, otherwise zero IPv6 address (::
). IPv6
Examples
Usage example