Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fullip = "172.16.20.51/24";
- const ip = fullip.split('/')[0];
- const subnet = fullip.split('/')[1];
- const ipslipt = ip.split('.');
- const binaryIp = [];
- const netAdreess = Math.pow(2, subnet);
- const hostAdress = Math.pow(2, (32-subnet));
- ipslipt.map(item=>{
- let singleIp = parseInt(item).toString(2);
- if(singleIp.length < 8){
- let shortestIp = 8 - (singleIp.length);
- for(let i = 1; i <= shortestIp;i++){
- singleIp = 0 + singleIp;
- }
- }
- binaryIp.push(singleIp);
- });
- console.log("Binary IP: " + binaryIp.join('.'));
- console.log("Network Address: " + netAdreess);
- console.log("Host Address: " + hostAdress);
Add Comment
Please, Sign In to add comment