ip-address
ip-address copied to clipboard
Subnet question
Hi, thanks for the NPM package. Maybe I'm just being stupid but when finding the subnet of an IP address seems incorrect, eg:
let netMask = new Address4('255.255.255.0');
returns /32
But normally, 255.255.255.0 returns /24 (as 8 + 8 + 8)
the default subnet of any single address when a subnet is not specified is /32--you could count the bits in the netmask to translate to a subnet though, e.g.:
let netMask = new Address4('255.255.255.0');
console.log(/^1+/.exec(netMask.binaryZeroPad())[0].length); // 24
this should probably be a static helper function on Address4, like Address4.netmaskToSubnet('255.255.255.0'), would that work for you?