So I'm told that the DBAs here are going to be storing IP addresses in a DECIMAL(39,0) field in our MySQL database.
How can I go about translating that into a String to pass on to our other applications?
Note: Our databases can't take any more load, so as much of the work as possible needs to be done in the Java application.
Note2: IPv6 support is a must.
Use
INET_NTOA
eg: SELECT INET_NTOA(num) AS ipaddr;
and
INET_ATON
eg: INSERT INTO addrTbl VALUES (..., INET_ATON('192.168.0.1'), ...)
This works because IPv4 was originally designed to have IP addresses defined as 32-bit numbers. The dot-decimal notation is for readbility.
Update
If you wish to perform the transformation from a number to a dot-decimal notation in Java, the MindProd site has an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With