close

MariaDB IP Address Conversion Functions:
 

########
# IPV4:
########

-- Address To Number:
MariaDB [test]> select inet_aton('10.0.2.15');
+------------------------+
| inet_aton('10.0.2.15') |
+------------------------+
|              167772687 |
+------------------------+
1 row in set (0.001 sec)

# Number to Address
MariaDB [test]> select inet_ntoa(167772687);
+----------------------+
| inet_ntoa(167772687) |
+----------------------+
| 10.0.2.15            |
+----------------------+
1 row in set (0.001 sec)


########
# IPV6
########

-- Address To Number:
MariaDB [test]> select hex(inet6_aton('fe80::ef99:177:ff9e:e769'));
+---------------------------------------------+
| hex(inet6_aton('fe80::ef99:177:ff9e:e769')) |
+---------------------------------------------+
| FE80000000000000EF990177FF9EE769            |
+---------------------------------------------+
1 row in set (0.001 sec)

# Number to Address
MariaDB [test]> select inet6_ntoa(unhex('FE80000000000000EF990177FF9EE769'));
+-------------------------------------------------------+
| inet6_ntoa(unhex('FE80000000000000EF990177FF9EE769')) |
+-------------------------------------------------------+
| fe80::ef99:177:ff9e:e769                              |
+-------------------------------------------------------+
1 row in set (0.001 sec)

 

arrow
arrow
    文章標籤
    MariaDB
    全站熱搜
    創作者介紹
    創作者 DanBrother 的頭像
    DanBrother

    DanBrother的部落格

    DanBrother 發表在 痞客邦 留言(0) 人氣()