Function chkIPRange (startIP, endIP, ip)
chkIPRange = false
myArray1 = split(startIP, ".")
myArray2 = split(endIP, ".")
myArray3 = split(ip, ".")
'myArray1 to Binary
for n = 0 to 3
myInt= CInt(myArray1(n))
binmyArray1 = binMyArray1 & dectobin(myInt)
next
document.write binmyArray1 & " - " & bintodec(binmyArray1) & "<br>"
'myArray2 to Binary
for n = 0 to 3
myInt= CInt(myArray2(n))
binmyArray2 = binMyArray2 & dectobin(myInt)
next
document.write binmyArray2 & " - " & bintodec(binmyArray2) & "<br>"
'myArray3 to Binary
for n = 0 to 3
myInt= CInt(myArray3(n))
binmyArray3 = binMyArray3 & dectobin(myInt)
next
document.write binmyArray3 & " - " & bintodec(binmyArray3) & "<br>"
if (bintodec(binmyArray1) <= bintodec(binmyArray3)) and (bintodec(binmyArray3) <= bintodec(binmyArray2)) then
chkIPRange = true
else
chkIPRange = false
end if
End Function
Function DecToBin(dIn)
DecToBin = ""
While dIn >= 1
if dIn Mod 2 then
DecToBin = "1" & DecToBin
else
DecToBin = "0" & DecToBin
end if
dIn = dIn \ 2
Wend
if len(DecToBin) < 8 then
for i = 1 to 8 - len(DecToBin)
DecToBin = "0" & DecToBin
next
end if
End Function
Function BinToDec(sIn)
Dim x
BinToDec = 0
For x = 1 To Len(sIn)
BinToDec = BinToDec + (CInt(Mid(sIn, x, 1)) * (2 ^ (Len(sIn) - x)))
Next
End Function
Probably could be cleaned up a bit more.
How it works;
Each of the four numbers in the i.p. address must be converted to binary (8 digits)
and concatenated e.g.
127.0.0.12 = 01111111.00000000.00000000.00001100
01111111.00000000.00000000.00001100 ends up as 01111111000000000000000000001100 and is then converted to decimal so
01111111000000000000000000001100 = 2130706444
Once each i.p. address is converted to decimal its easy to compare them.