MySQL INET6_ATON() Function
In MySQL, the INET6_ATON()
function converts the specified IPv6 or IPv4 address to a binary string of numbers representing the address in network byte order.
The INET6_ATON()
function is the inverse of the INET6_NTOA()
function.
INET6_ATON()
Syntax
Here is the syntax of the MySQL INET6_ATON()
function:
INET6_ATON(ip)
Parameters
ip
- Required. An IPv6 or IPv4 address.
Return value
The MySQL INET6_ATON()
function converts the specified IPv6 or IPv4 address to a binary string of numbers representing the address in network byte order.
If the argument is NULL
, the function will return NULL
.
INET6_ATON()
Examples
Use INET6_ATON()
to process IPv6 addresses:
SELECT HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089'));
+----------------------------------------------+
| HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089')) |
+----------------------------------------------+
| FDFE0000000000005A55CAFFFEFA9089 |
+----------------------------------------------+
Here, we use the HEX()
function to convert the returned binary string to hexadecimal characters.
Use INET6_ATON()
to process IPv4 addresses:
SELECT HEX(INET6_ATON('192.168.1.100'));
+----------------------------------+
| HEX(INET6_ATON('192.168.1.100')) |
+----------------------------------+
| C0A80164 |
+----------------------------------+