Skip to content

ipInSubnet

Description

Return true if an IP address belongs to a given subnet, otherwise return false.

Syntax

Like many functions in DataPrime, ipInSubnet supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

ipInSubnet(ip: string, ipPrefix: string): bool
(ip: string).ipInSubnet(ipPrefix: string): bool

Arguments

NameTypeRequiredDescription
ipstringtrueThe IP address to test
ipPrefixstringtrueThe CIDR range to check against, e.g. 154.67.8.0/24

Example

Use case: Filter documents by subnet membership

Check if the field ip_address belongs to the subnet 154.67.8.0/24. Documents with matching IPs are included in the result set, while others are excluded.

{
    "ip_address": "154.67.8.42"
},
{
    "ip_address": "10.0.0.5"
}
filter ipInSubnet(ip_address, '154.67.8.0/24')
filter ip_address.ipInSubnet('154.67.8.0/24')

Output

{
    "ip_address": "154.67.8.42"
}