Skip to content

Instantly share code, notes, and snippets.

@arth2o
Created November 19, 2015 10:58
Show Gist options
  • Save arth2o/6f2a308c7b00bc241533 to your computer and use it in GitHub Desktop.
Save arth2o/6f2a308c7b00bc241533 to your computer and use it in GitHub Desktop.
JavaScript IpToLong and IpFromLong
ipToLong = function toInt(ip){
var ipl=0;
ip.split('.').forEach(function( octet ) {
ipl<<=8;
ipl+=parseInt(octet);
});
return(ipl >>>0);
};
ipFromLong = function fromInt(ipl){
return ( (ipl>>>24) +'.' +
(ipl>>16 & 255) +'.' +
(ipl>>8 & 255) +'.' +
(ipl & 255) );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment