ipv6_compare function to compare two IPv6 addresses and determine their relative order. This function helps you evaluate whether one address is less than, equal to, or greater than another. It returns -1, 0, or 1 accordingly.
You can use ipv6_compare in scenarios where IPv6 addresses are relevant, such as sorting traffic logs, grouping metrics by address ranges, or identifying duplicate or misordered entries. It’s especially useful in network observability and security use cases where working with IPv6 is common.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
Splunk SPL doesn’t have a built-in function for directly comparing IPv6 addresses. Users often work around this limitation by converting the addresses into a comparable numeric format using external scripts or custom commands.
ANSI SQL users
ANSI SQL users
ANSI SQL doesn’t natively support IPv6 comparisons. Typically, users must store IPv6 addresses as strings or binary values and write custom logic to compare them.
Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
ipv6_1 | string | The first IPv6 address to compare. |
ipv6_2 | string | The second IPv6 address to compare. |
Returns
An integer that represents the result of the comparison:-1ifipv6_1is less thanipv6_20ifipv6_1is equal toipv6_21ifipv6_1is greater thanipv6_2
Example
Useipv6_compare to identify whether requests from certain IPv6 addresses fall into specific ranges or appear out of expected order.
Query
| _time | uri | method | status | comparison |
|---|---|---|---|---|
| 2025-06-29T22:10:00Z | /products/1 | GET | 200 | -1 |
List of related functions
- ipv6_is_match: Checks if an IPv6 address matches a given subnet. Use it for range filtering instead of sorting or comparison.
- ipv4_is_private: Determines whether an IPv4 address is in a private range. Use this to filter non-public traffic.
- ipv4_compare: Works the same way as
ipv6_comparebut for IPv4 addresses. Use it when your data contains IPv4 instead of IPv6.