You can use the function INET_ATON()
. The inet_aton converts the past address (including dots) to a valid address structure (binary).
Example:
- 10.0.0.100 = 10 256³ + 0 256² + 0 256 + 100 = 167772260
- 10.0.0.11 = 10 256³ + 0 256² + 0 256 + 11 = 167772171
So, your script would look this way:
SELECT IPS FROM ipvalidos WHERE REDE ='{$rede}' ORDER BY INET_ATON(IPS)
I put in the Github the file example_inet_aton.sql for future references and get registered. If you want to see working, access here in the paiza..
It is also possible to carry out the reverse operation of inet_aton
, that would be using the inet_ntoa
. From a binary value (structure) it returns the address in string format (including points).
To deepen and understand more about function, see here in the documentation of Mysql itself.
Thanks @Viana! Excellent solution!!!
– Anderson Fidelis