Skip to content

Instantly share code, notes, and snippets.

@divinity76
Created May 17, 2020 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divinity76/2246c7f27588ec518621de4c6b4f43e9 to your computer and use it in GitHub Desktop.
Save divinity76/2246c7f27588ec518621de4c6b4f43e9 to your computer and use it in GitHub Desktop.
SQLite INET_ATON / ip2long / INET_NTOA / long2ip
-- 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