ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaku_5.4.0.1/rzakutrbsubnetcalc.htm

419 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 4.0//EN">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<title>TCP/IP troubleshooter</title>
<meta name="Copyright" content="Copyright (c) 2004 by IBM Corporation">
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<script language="Javascript" type="text/javascript" src="../../iccommon.js"></script>
<script type="text/javascript" language="Javascript">
var badIPError = "IP addresses and subnet masks must be four decimal numbers between 0 and 255 separated by a period. For example, 10.1.2.3.";
var badFirstSegmentError = "The first segment of an IP address cannot be 0.";
var blankMsg = "You must fill this field in.";
var text1 = " Your local address is the same as the subnet address for your subnet. This may make your local address unroutable in your network.";
var text2 = " Your local address is the same as the broadcast address for your subnet. This may make your local address unroutable in your network.";
var text3 = "Your local and remote addresses are within the same subnet.";
//START NON-TRANSLATABLE
//NS4 = (document.layers) ? 1 : 0;
//IE4 = (document.all) ? 1 : 0;
//ver4 = (NS4 || IE4) ? 1 : 0;
var theSeg;
var maskArray;
var inAddyArray;
var pingAddyArray;
var highAddy;
var lowAddy;
var output;
var answer = false;
var ran = false;
function isValidSubnetMask (address) {
var addrPart = address.split(".");
var testParts = new Array("254","252","248","240","224","192","128","0");
var validated=0;
if (addrPart[0]=="255"){
if (addrPart[1]=="255") {
if (addrPart[2]=="255") {
for (x=0;x<testParts.length;x++) {
if (addrPart[3]==testParts[x]) {validated=1;}
}
}//end if addrpart2=255
else {//else addrpart 2<255
if (addrPart[3]=="0") {
for (x=0;x<testParts.length;x++) {
if (addrPart[2]==testParts[x]) {validated=1;}
}
}
}//end else addrpart2
}//end if addrpart1==255
else {//else addrpart1<255
if ((addrPart[2]=="0")&&(addrPart[3]=="0")) {
for (x=0;x<testParts.length;x++) {
if (addrPart[1]==testParts[x]) {validated=1;}
}
}
}//end else addrpart1
}//end addrpart0==255
else {//else addrpart0<255
if ((addrPart[1]=="0")&&(addrPart[2]=="0")&&(addrPart[3]=="0")) {
for (x=0;x<testParts.length-1;x++) {
if (addrPart[0]==testParts[x]) {validated=1;}
}
}
}//end else addrpart0
if (validated == 1){ return true;}
else {return false;}
}
function isValidIPAddress (address){
var segment = address.split(".");
if (segment[0] == 0) { alert(badFirstSegmentError); return false;}
for (x=0; x<segment.length; x++){
checknum = segment[x];
if ((checknum < 0) ||(checknum > 255) || (isNaN(checknum))) {
alert(badIPError);
return false;
}
}
address = segment.join(".");
var valAddr = /^((([0-9-]){1,3})[\.]){3}(([0-9-]){1,3})$/;
return valAddr.test(address);
}
/* This function checks to see if the local IP address happens to match
the calculated subnet and broadcast addresses. If there is a match,
an additional message is attached to the user output. It takes three
arguements: the local IP address, and the start and end IP addresses.
*/
function checkIP(local, start, end){
if (local.join(".") == start.join(".")){
output = output + text1;
}
if (local.join(".") == end.join(".")){
output = output + text2;
}
}
/* This function takes a form object as an arguement. It checks to see
if the form's text fields are empty. If it finds an empty field, it
returns false; else it returns true.
*/
function checkBlanks(formObj){
if (formObj.elements[0].value == ""){
alert(blankMsg);
formObj.elements[0].focus();
return false;
}
else if (formObj.elements[1].value == ""){
alert(blankMsg);
formObj.elements[1].focus();
return false;
}
else if (formObj.elements[2].value == ""){
alert(blankMsg);
formObj.elements[2].focus();
return false;
}
else { return true;}
}
/* This function take a form object as an arguement. It gets the IP addresses and does
IP calculations. Then it outputs an answer as to whether a local and remote IP address
are on the same subnet.
*/
function checkSubnet(){
formObj = eval("document.subnetform");
// Getting the form values into variables
inAddy = formObj.localip.value;
pingAddy = formObj.remoteip.value;
inMask = formObj.mask.value;
writeIt("", 'results');
if (checkBlanks(formObj)){ //check for blank fields
if (isValidIPAddress(inAddy) && isValidIPAddress(pingAddy) && isValidSubnetMask(inMask)){ //check validity of input
// Changing the IP addresses into arrays
maskArray = inMask.split(".");
inAddyArray = inAddy.split(".");
pingAddyArray = pingAddy.split(".");
highAddy = inAddy.split(".");
lowAddy = inAddy.split(".");
if ((maskArray.length == 4) && (inAddyArray.length == 4) && (pingAddyArray.length == 4)) {
ran = true;
rangeFactor = findFactor(maskArray);
myMod = inAddyArray[theSeg] % rangeFactor;
ipRangeStart = inAddyArray[theSeg] - myMod;
if (ipRangeStart < 0 ){ ipRangeStart = 0;}
lowAddy[theSeg] = ipRangeStart;
ipRangeEnd = ipRangeStart + rangeFactor;
highAddy[theSeg] = ipRangeEnd;
adjustEndRange();
//Outputting to the division;
if (isBetween(pingAddyArray, highAddy, lowAddy, theSeg)){ // the address is in the range
output = text3;
checkIP(inAddyArray, lowAddy, highAddy);
answer = true;
} else { //the address is not between;
//END NON-TRANSLATABLE
output = "Your local and remote addresses are not within the same subnet. The range of IP addresses for the local address is " + lowAddy.join(".") + " through " + highAddy.join(".") + ".";
//START NON-TRANSLATABLE
}
//output = output + "<form><input type='button' value='Close' onClick='closeThis()'><\/form>";
writeIt(output, 'results');
}
else { alert(badIPError);}
}
else {alert(badIPError);}
}
}
function closeThis() {
if ( ran ) {
if (answer) {
opener.form1.rad[0].checked = true;
}
else {
opener.form1.rad[1].checked = true;
}
}
window.close();
}
/* This function adjusts the high and low IP addresses after the ranges have been
calculated.
*/
function adjustEndRange(){
switch ( theSeg) {
case 3 :
highAddy[3]--;
break;
case 2 :
lowAddy[3] = 0;
highAddy[2]--;
highAddy[3] = 255;
break;
case 1:
highAddy[3]=255;
highAddy[2]=255;
highAddy[1]--;
lowAddy[2]=0;
lowAddy[3]=0;
}
}
/* This function takes four arguements. The remote (ping) address, the high and low IP ranges,
and the segment number. It returns true or false if the remote IP address is between (or not)
the high and low IP address range
*/
function isBetween(ping, high, low, seg){
for (i=0; i <= seg-1; i++){
if ( parseInt(ping[i]) != parseInt(high[i])){ //checking to make sure segments match
return false;
}
} //end-for
var between = ((parseInt(ping[seg]) >= parseInt(low[seg])) && (parseInt(ping[seg]) <= parseInt(high[seg]))) ? true : false;
return between;
}
/* This function takes the subnet mask as an array as an arguement. Based on the mask, it
determines which segment of the mask determines the IP range. It sets that segment as a
global value called theSeg and returns the factor.
*/
function findFactor(tmpA){
var binNum;
for (i=3; i >= 0; i--){
binNum = "";
binRep = dec2bin(tmpA[i]);
// document.write("<P>" + tmpA[i] + "---" + binRep + "</p>");
for (j=binRep.length-1; j >= 0; j--){
if (binRep.charAt(j) == 1) {
binNum = "1" + binNum;
binNum=parseInt(binNum);
theSeg = i;
return bin2dec(binNum);
}
else {
binNum = binNum + "0";
}
}
}
}
/* This function converts a binary number to a decimal number and then returns
the decimal number.
*/
function bin2dec(binNum){
return parseInt(binNum, 2);
}
/* This function converts a decimal number to binary number and
returns the binary number.
*/
function dec2bin(decNum){
currnum = 128;
var binNum;
if(decNum >= currnum) {
binNum = "1";
decNum = decNum - currnum;
currnum = currnum / 2;
}
else {
binNum = "0";
currnum = currnum / 2;
}
for (p = 1; p <= 7; p++) {
if(decNum >= currnum){
binNum = binNum + "1";
decNum = decNum - currnum;
currnum = currnum / 2;
}
else {
binNum = binNum + "0";
currnum = currnum / 2;
}
}
return binNum;
}
function writeIt(text,id) {
if (document.getElementById){
x = document.getElementById(id);
x.innerHTML = text;
}
else if (document.all){
x = document.all[id];
x.innerHTML = text;
}
else if (document.layers) {
x = document.layers[id];
text2 = '<P CLASS="testclass">' + text + '<\/P>';
x.document.open();
x.document.write(text2);
x.document.close();
}
}
function subnetCalc(showResults,on)
{
if (isNS && !isNS6) {
document.layers[showResults].visibility = "show";
} else {
document.all[showResults].style.visibility = "visible";
}
}
//Pass true if IP is on same subnet as remote interface, false otherwise
function closeWindowAndWriteToTroubleshooter(isIPOnSameSubnet) {
if (isIPOnSameSubnet == true) {
//Set value on troubleshooter page to Yes
window.opener.document.form1.rad[0].checked = true;
} else {
//Set value on troubleshooter page to N0
window.opener.document.form1.rad[1].checked = true;
}
window.close();
}
//END NON-TRANSLATABLE
</script>
</head>
<body onUnload="closeThis()">
<script type="text/javascript" language="Javascript"></script>
<form name="subnetform">
<h2>Calculate subnet</h2>
<p>Complete the following fields, click Calculate, and view the results.</p>
<TABLE width="80%">
<TR>
<td width="60%" nowrap>
<LABEL for="LocalIP">Specify the IP address associated with your local interface:</LABEL>
</td>
<TD align="left">
<INPUT type="number" name="localip" size="15" id="LocalIP" value="">&nbsp;
</TD>
</TR>
<TR>
<TD width="60%" nowrap>
<LABEL for="LocalMask">Specify the subnet mask you are using for the local IP address:</LABEL>
</TD>
<TD align="left">
<INPUT type="number" name="mask" size="15" id="LocalMask" value="">
</TD>
</TR>
<TR>
<TD width="60%" nowrap>
<LABEL for="RemoteIP">Specify the IP address associated with the remote interface:</LABEL>
</TD>
<TD align="left">
<INPUT type="number" name="remoteip" size="15" id="RemoteIP" value="">&nbsp;
</TD>
</TR>
<tr></tr>
</TABLE>
</form>
<table>
<tr>
<td width="50%">
<div id="results" style="position:relative; background:lightgrey; border:double; border-width:1px; padding:10px; width: 450px;" name="results">
<P>&nbsp;</p><P>&nbsp;</p><P>&nbsp;</p><P>&nbsp;</p>
</div>
</td>
</tr>
</table>
<form><p><center>
<INPUT type="button" name="calculate" value="Calculate" onclick= "checkSubnet();"> <INPUT type="button" name="closeButton" value="Close window" onclick= "closeThis()">
</center></p></form>
</body>
</html>