-
-
Save marcozink/bb8dbec5306992b832d3154ce78e5c8e to your computer and use it in GitHub Desktop.
javascript conversion from ip address to long integer and vice versa
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
function int2ip (ipInt) { | |
return ( (ipInt>>>24) +'.' + (ipInt>>16 & 255) +'.' + (ipInt>>8 & 255) +'.' + (ipInt & 255) ); | |
} |
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
function ip2int(ip) { | |
return ip.split('.').reduce(function(ipInt, octet) { return (ipInt<<8) + parseInt(octet, 10)}, 0) >>> 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment