First you need to get it into a number, use this function:-
function IPToNumber(s)
{
var arr = s.split(".");
var n = 0
for (var i = 0; i < 4; i++)
{
n = n * 256
n += parseInt(arr[i],10)
}
return n;
}
Looking at you spec, whilst you seem to list a series of ranges those ranges appear to be contiguous to me, that is can be simplified to (224.0.0.0 to 239.255.255.255). Hence you can test with:-
var min = IPToNumber("224.0.0.0");
var max = IPToNumber("239.255.255.255");
var ipNum = IPToNumber(sTestIP);
var isValid = (ipNum != 0 && (ipNum < min || ipNum > max))
Note of course that without knowledge of the destinations subnet you can't tell whether the address is the network address or the broadcast address for that subnet.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…