Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Google App Script function (javascript) to check if an IP address belongs to a given range.
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