Hola,
estoy tratando de hacer un script que me sume un numero a una ip y me la verifique antes de devolvermela.
He mirado por ahi y he encontrado este Script para parsear ips, pero no consigo sumarle un numero a la ip.
Si alguien me pudiera echar una mano, le estaria muy agradecido.
El Script es:
Código:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function verifyIP (IPvalue, Ipnum) {
errorString = "";
theName = "IPaddress";
var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var ipArray = IPvalue.match(ipPattern);
var IpSum =Ipnum;
if (IPvalue == "0.0.0.0")
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
else if (IPvalue == "255.255.255.255")
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
if (ipArray == null)
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
else {
for (i = 0; i < 4; i++) {
thisSegment = ipArray[i];
if (thisSegment > 255) {
errorString = errorString + theName + ': '+IPvalue+' is not a valid IP address.';
i = 4;
}
if ((i == 0) && (thisSegment > 255)) {
errorString = errorString + theName + ': '+IPvalue+' is a special IP address and cannot be used here.';
i = 4;
}
}
}
extensionLength = 3;
if (errorString == "")
alert (+IPvalue+" iThat is a valid IP address.");
else
alert (errorString);
}
// End -->
</script>
<form>
IP Address:
<input size=15 name="IPvalue">
<input size=15 name="IPnum">
<input type="submit" value="Verify" onClick="verifyIP(IPvalue.value)";>
</form>