Created
December 17, 2017 22:45
-
-
Save ArisBee/c82197c9333cd680572fa97ff73acc67 to your computer and use it in GitHub Desktop.
A Google App Script function (javascript) to check if an IP address belongs to a given range.
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 isInRange(ip, firstRangeIp, lastRangeIp) | |
{ | |
var ipArr = ip.split("."); | |
var firstArr = firstRangeIp.split("."); | |
var lastArr = lastRangeIp.split("."); | |
var pos = 0 | |
for(i=0;i<4;i++) | |
{ | |
if(Number(ipArr[i])<Number(firstArr[i])) | |
return false; | |
else if (Number(ipArr[i])==Number(firstArr[i])) pos=i; | |
else{ | |
if(Number(ipArr[pos+1])>Number(lastArr[pos+1])) | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment