Created
          March 18, 2016 07:04 
        
      - 
      
 - 
        
Save monkeym4ster/7eff5843863f2b373a1e to your computer and use it in GitHub Desktop.  
    JavaScript IP to long
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | var ip; | |
| ip = {}; | |
| ip.toLong = function toInt(ip){ | |
| var ipl=0; | |
| ip.split('.').forEach(function( octet ) { | |
| ipl<<=8; | |
| ipl+=parseInt(octet); | |
| }); | |
| return(ipl >>>0); | |
| }; | |
| ip.fromLong = 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