Created
November 19, 2015 10:58
-
-
Save arth2o/6f2a308c7b00bc241533 to your computer and use it in GitHub Desktop.
JavaScript IpToLong and IpFromLong
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
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