INET6_NTOA() :
This function in MySQL takes an IPv6 or IPv4 network address represented in numeric form as a binary string and it returns the string representation of the address as a string in the connection character set. It returns NULL if the address is not valid.
Syntax :
INET6_NTOA(expr)
Parameter : This function accepts only one parameter.
-
expr –
Input IPv4 or IPv6 address
Returns :
It returns the string representation of the address
Example-1 :
Checking the equivalent dotted-quad string representation for the following address ‘ 0A000511’ with the help of INET6_NTOA and UNHEX Function. As it is a valid IPv4 address we will get the result in a dotted string.
SELECT INET6_NTOA(UNHEX('0A000511')) AS Address_In_DottedString ;
Output :
ADDRESS_IN_DOTTEDSTRING |
---|
10.0.5.17 |
Example-2 :
Checking the equivalent dotted-quad string representation for the following address ‘ FCBE0000000000005C34CABDFEFA6312’ with the help of INET6_NTOA and UNHEX Function. As it is a valid IPv6 address we will get the result in a dotted string.
SELECT INET6_NTOA(UNHEX('FCBE0000000000005C34CABDFEFA6312')) AS Address_In_DottedString ;
Output :
ADDRESS_IN_DOTTEDSTRING |
---|
fcbe::5c34:cabd:fefa:6312 |
Example-3 :
Checking the equivalent dotted-quad string representation for the following address ‘ 456A’ with the help of INET6_NTOA and UNHEX Function. As it is not a valid IPv6 or IPv4 address we will get a NULL result.
SELECT INET6_NTOA(UNHEX('456A')) AS Address_In_DottedString ;
Output :
ADDRESS_IN_DOTTEDSTRING |
---|
NULL |
Example-4 :
Checking the equivalent dotted-quad string representation for the following address ‘ 9.7.5.8’ with the help of INET6_NTOA and INET6_ATON Function. As it is not a valid IPv6 or IPv4 address we will get the result in a dotted string.
SELECT INET6_NTOA(INET6_ATON('9.7.5.8')) AS Address_In_DottedString ;
Output :
ADDRESS_IN_DOTTEDSTRING |
---|
9.7.5.8 |