Created
May 17, 2020 10:42
-
-
Save divinity76/2246c7f27588ec518621de4c6b4f43e9 to your computer and use it in GitHub Desktop.
SQLite INET_ATON / ip2long / INET_NTOA / long2ip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- found here https://vcert.blogspot.com/2013/04/ip2long-and-long2ip-in-excel.html?showComment=1589707642294#c2711257816799880812 | |
-- copyright unknown.. | |
-- long2ip: | |
SELECT IPint, ((IPint >> 24) & 255) ||'.'|| | |
((IPint >> 16) & 255) ||'.'|| ((IPint >> 8) & 255) ||'.'|| ((IPint ) & 255) | |
FROM iptest; | |
-- found here https://vcert.blogspot.com/2013/04/ip2long-and-long2ip-in-excel.html?showComment=1589707642294#c2711257816799880812 | |
-- copyright unknown.. | |
-- ip2long: | |
SELECT CAST(REPLACE(ip,LTRIM(ip,"1234567890"),"")*16777216 | |
+RTRIM(RTRIM(RTRIM(LTRIM(LTRIM(ip,"1234567890"),"."),"1234567890"),"."),"1234567890")*65536 | |
+SUBSTR(LTRIM(RTRIM(LTRIM(LTRIM(ip,"1234567890"),"."),"1234567890"),"1234567890"),2)*256 | |
+REPLACE(ip,RTRIM(ip,"1234567890"),"") AS INTEGER) FROM iptest; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment