You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
713 B
JavaScript
37 lines
713 B
JavaScript
function h_countbitsfromleft(num) {
|
|
if (num == 255)
|
|
return(8);
|
|
|
|
var i = 0;
|
|
var bitpat = 0xff00;
|
|
while (i < 8) {
|
|
if (num == (bitpat & 0xff))
|
|
return(i);
|
|
|
|
bitpat = bitpat >> 1;
|
|
i++;
|
|
}
|
|
return(Number.NaN);
|
|
}
|
|
|
|
function numberOfBitsOnNetMask(netmask) {
|
|
var total = 0;
|
|
var t = netmask.split('.');
|
|
for (var i = 0; i <= 3 ; i++)
|
|
total += h_countbitsfromleft(t[i]);
|
|
|
|
return total;
|
|
}
|
|
|
|
function getNetworkAddress(ipaddress, netmask) {
|
|
return fixIP(ntoa(aton(ipaddress) & aton(netmask)));
|
|
}
|
|
|
|
function getBroadcastAddress(network, netmask) {
|
|
return fixIP(ntoa(aton(network) ^ (~ aton(netmask))));
|
|
}
|
|
|
|
function getAddress(ipaddress, network) {
|
|
return fixIP(ntoa((aton(network)) + (aton(ipaddress))));
|
|
}
|