-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
47 lines (40 loc) · 1.22 KB
/
script.js
File metadata and controls
47 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const readline = require("readline");
var networks;
var clients;
var classOfNetwork;
var classA = '255.0.0.0';//255 means it doesnt change
var classB = '255.255.0.0';
var classC = '255.255.255.0';
prompt();
function prompt() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question("Class of Network: ", (answer) => {
classOfNetwork = answer;
rl.question("How many networks: ", (answer) => {
networks = parseInt(answer);
rl.question("How many clients: ", (answer) => {
clients = parseInt(answer);
if (networks > 0 && clients > 0) {
const subnetPrefix = calculateSubnetPrefix(networks);
console.log("Class of Network: ",classOfNetwork);
console.log("Networks:", networks);
console.log("Clients per Network:", clients);
rl.close();
} else {
console.log(
"Invalid input. Networks and clients must be greater than 0."
);
rl.close();
}
});
});
});
}
function calculateSubnetPrefix(clientsPerNetwork) {
var subnetBits = Math.ceil(Math.log2(clientsPerNetwork + 2));
var subnetMask = 32 - subnetBits;
return subnetMask;
}