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. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
ipInSubnet(ip: string, ipPrefix: string): bool
(ip: string).ipInSubnet(ipPrefix: string): bool
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
ip | string | true | The IP address to test |
ipPrefix | string | true | The 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.
Example data
{
"ip_address": "154.67.8.42"
},
{
"ip_address": "10.0.0.5"
}
Example query
- Function notation
- Method notation
filter ipInSubnet(ip_address, '154.67.8.0/24')
filter ip_address.ipInSubnet('154.67.8.0/24')
Example output
{
"ip_address": "154.67.8.42"
}