Collections:
INET_ATON() - IP Address String to Number
How to convert an IP address from string format to number using the INET_ATON() function?
✍: FYIcenter.com
INET_ATON(ip) is a MySQL built-in function that
converts an IP address from string format to number.
It uses the following conversion formula:
INET_ATON('p1.p2.p3.p4') = INET_ATON(p1×2563 + p2×2562 + p3×256 + p4
For example:
SELECT INET_ATON('10.0.5.9'), 10*POW(256,3) + 0*POW(256,2) + 5*256 + 9;
-- +-----------------------+------------------------------------------+
-- | INET_ATON('10.0.5.9') | 10*POW(256,3) + 0*POW(256,2) + 5*256 + 9 |
-- +-----------------------+------------------------------------------+
-- | 167773449 | 167773449 |
-- +-----------------------+------------------------------------------+
SELECT INET_ATON('127.0.0.1'), 127*POW(256,3) + 0*POW(256,2) + 0*256 + 1;
-- +------------------------+-------------------------------------------+
-- | INET_ATON('127.0.0.1') | 127*POW(256,3) + 0*POW(256,2) + 0*256 + 1 |
-- +------------------------+-------------------------------------------+
-- | 2130706433 | 2130706433 |
-- +------------------------+-------------------------------------------+
Reference information of the INET_ATON() function:
INET_ATON(ip): int Converts an IP address from string format to number. Arguments, return value and availability: ip: Required. The IP address in string format. int: Return value. The IP address as a number. Available since MySQL 4.0.
Related MySQL functions:
⇒ INET_NTOA() - IP Address Number to String
⇐ IFNULL() - Replacing NULL Value
2023-12-19, 1406🔥, 0💬
Popular Posts:
Where Is the Export Dump File Located in Oracle? If you are not specifying the dump directory and fi...
How To Convert Binary Strings into Hexadecimal Character Strings in SQL Server? When a query returns...
How To Disable a Login Name in SQL Server? If you want temporarily disable a login name, you can use...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...