ipv6_compare()
Compares two IPv6 or IPv4 network address strings. The two IPv6 strings are parsed and compared while accounting for the combined IP-prefix mask calculated from argument prefixes, and the optional PrefixMask argument.
ipv6_compare('::ffff:7f00:1', '127.0.0.1') == 0
ipv6_compare('fe80::85d:e82c:9446:7994', 'fe80::85d:e82c:9446:7995') < 0
ipv6_compare('192.168.1.1/24', '192.168.1.255/24') == 0
ipv6_compare('fe80::85d:e82c:9446:7994/127', 'fe80::85d:e82c:9446:7995/127') == 0
ipv6_compare('fe80::85d:e82c:9446:7994', 'fe80::85d:e82c:9446:7995', 127) == 0
The function can accept and compare arguments representing both IPv6 and IPv4 network addresses. However, if the caller knows that arguments are in IPv4 format, use ipv4_is_compare() function. This function will result in better runtime performance.
Syntax
ipv6_compare(Expr1, Expr2[ ,PrefixMask])
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
| Expr1 | String | ✓ | A string expression representing an IPv4/IPV6 address. IPv4 strings can be masked using IP-prefix notation. |
| Expr2 | String | ✓ | A string expression representing an IPv4/IPV6 address. IPv4 strings can be masked using IP-prefix notation. |
| PrefixMask | Number or String | An integer from 0 to 32 representing the number of most-significant bits that are taken into account. |
IP-prefix notation
It's common practice to define IP addresses with IP-prefix notation using a slash (/) character. The IP address to the LEFT of the slash (/) is the base IP address, and the number (1 to 127) to the RIGHT
of the slash (/) is the number of contiguous 1 bits in the netmask.
For example, fe80::85d:e82c:9446:7994/120 will have an associated net/subnetmask containing 120 contiguous bits.
Returns
0: If the long representation of the first IPv6 string argument is equal to the second IPv6 string argument.1: If the long representation of the first IPv6 string argument is greater than the second IPv6 string argument.-1: If the long representation of the first IPv6 string argument is less than the second IPv6 string argument.null: If conversion for one of the two IPv6 strings wasn't successful.
Example
Compare IPs using the IP-prefix notation specified inside the IPv6/IPv4 strings
Example
Compare IPs using IP-prefix notation specified inside the IPv6/IPv4 strings and as additional argument of the ipv6_compare() function
events_all
| project src_ipv6, result=ipv6_compare(src_ipv6,'2001:db8:ffff:ffff:ffff:ffff:ffff:eeee')
| distinct result
Results
| result |
|---|
| -1 |
| -1 |
| 0 |
| 1 |