IS_IP_ADDRESS_IN_RANGE
Descriptionβ
Determine whether the IP (IPv4 or IPv6) address is included in the network represented by CIDR notation.
Syntaxβ
IS_IP_ADDRESS_IN_RANGE(ip_str, cidr_prefix)
Parametersβ
Parameter | Description |
---|---|
<ip_str> | An IPv4 or IPv6 address of type String |
<cidr_prefix> | The cidr prefix |
Return Valueβ
If the address is included in the network represented by CIDR notation, returns true; otherwise, return false.
- If input is NULL, the function returns NULL.
Exampleβ
SELECT is_ip_address_in_range('127.0.0.1', '127.0.0.0/8') as v4, is_ip_address_in_range('::ffff:192.168.0.1', '::ffff:192.168.0.4/128') as v6, is_ip_address_in_range('127.0.0.1', NULL) as nil;
+------+------+------+
| v4 | v6 | nil |
+------+------+------+
| 1 | 0 | NULL |
+------+------+------+