IS_IP_ADDRESS_IN_RANGE

IS_IP_ADDRESS_IN_RANGE

Description

Syntax

BOOLEAN IS_IP_ADDRESS_IN_RANGE(STRING ip_str, STRING cidr_prefix)

Determine whether the IP (IPv4 or IPv6) address is included in the network represented by CIDR notation. If yes, return true; otherwise, return false.

Example

  1. mysql> SELECT is_ip_address_in_range('127.0.0.1', '127.0.0.0/8');
  2. +----------------------------------------------------+
  3. | is_ip_address_in_range('127.0.0.1', '127.0.0.0/8') |
  4. +----------------------------------------------------+
  5. | 1 |
  6. +----------------------------------------------------+
  7. mysql> SELECT is_ip_address_in_range('::ffff:192.168.0.1', '::ffff:192.168.0.4/128');
  8. +------------------------------------------------------------------------+
  9. | is_ip_address_in_range('::ffff:192.168.0.1', '::ffff:192.168.0.4/128') |
  10. +------------------------------------------------------------------------+
  11. | 0 |
  12. +------------------------------------------------------------------------+
  13. mysql> SELECT is_ip_address_in_range('127.0.0.1', NULL);
  14. +-------------------------------------------+
  15. | is_ip_address_in_range('127.0.0.1', NULL) |
  16. +-------------------------------------------+
  17. | NULL |
  18. +-------------------------------------------+

Keywords

IS_IP_ADDRESS_IN_RANGE, IP