Collections:
IS_IPV4_COMPAT() - IPv4-Compatible IPv6 Address
How to detect an IPv6 Address that is IPv4 compatible using the IS_IPV4_COMPAT() function?
✍: FYIcenter.com
IS_IPV4_COMPAT(ip) is a MySQL built-in function that
returns 1 if the given IPv6 address is IPv4-compatible, 0 otherwise.
The IPv6 address must be given in number format.
An IPv4-compatible IPv6 address has 12 leading bytes of '00'. The last 4 bytes can form an IPv4 address. For example:
SELECT IS_IPV4_COMPAT('::10.0.5.9');
-- +------------------------------+
-- | IS_IPV4_COMPAT('::10.0.5.9') |
-- +------------------------------+
-- | 0 |
-- +------------------------------+
SELECT IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9'));
-- +------------------------------------------+
-- | IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9')) |
-- +------------------------------------------+
-- | 1 |
-- +------------------------------------------+
SELECT HEX(INET_ATON('10.0.5.9')), HEX(INET6_ATON('::10.0.5.9'));
-- +----------------------------+----------------------------------+
-- | HEX(INET_ATON('10.0.5.9')) | HEX(INET6_ATON('::10.0.5.9')) |
-- +----------------------------+----------------------------------+
-- | A000509 | 0000000000000000000000000A000509 |
-- +----------------------------+----------------------------------+
SELECT IS_IPV4_COMPAT(INET6_ATON('::a000:0509'));
-- +-------------------------------------------+
-- | IS_IPV4_COMPAT(INET6_ATON('::a000:0509')) |
-- +-------------------------------------------+
-- | 1 |
-- +-------------------------------------------+
SELECT IS_IPV4_COMPAT(INET6_ATON('::ffff:10.0.5.9'));
-- +-----------------------------------------------+
-- | IS_IPV4_COMPAT(INET6_ATON('::ffff:10.0.5.9')) |
-- +-----------------------------------------------+
-- | 0 |
-- +-----------------------------------------------+
Reference information of the IS_IPV4_COMPAT() function:
IS_IPV4_COMPAT(ip): boolean
Returns TRUE if and only if the given IPv6 address is IPv4-compatible.
Arguments, return value and availability:
ip: Required. The IPv6 address to be examined.
boolean: Return value.
TRUE if and only if the given IPv6 address is IPv4-compatible.
Available since MySQL 4.0.
Related MySQL functions:
⇒ IS_IPV4_MAPPED() - IPv4-Mapped IPv6 Address
⇐ IS_IPV4() - Detecting IPv4 Address
2026-02-02, 1223🔥, 0💬
Popular Posts:
How to execute statements in loops in SQL Server Transact-SQL? How to use WHILE ... loops? You can u...
How To Install Oracle Database 10g XE in Oracle? To install 10g universal edition, double click, Ora...
Where to find SQL Server database server tutorials? Here is a collection of tutorials, tips and FAQs...
How To Install PHP on Windows in MySQL? The best way to download and install PHP on Windows systems ...
What Are Out-of-Range Errors with DATETIME values in SQL Server Transact-SQL? When you enter DATETIM...