-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
133 lines (125 loc) · 5.04 KB
/
index.html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Subneteo</title>
<link rel="stylesheet" href="./CSS/normalize.css" />
<link rel="stylesheet" type="text/css" href="./CSS/style.css" />
</head>
<body>
<div class="container" id="main-container">
<h1>Subneteo - AYAR</h1>
<div class="container__option" id="Option1">
<h2>1. Conversor a IP Binaria</h2>
<label for="IPDecimal-R1">IP Decimal:</label>
<input type="text" name="IPDecimal-R1" id="IPDecimal-R1" />
<p id="IPBinaria-R1"></p>
<input type="button" value="Convertir" onclick="Ex1();" />
</div>
<div class="container__option">
<h2>Subneteo por Hosteos</h2>
</div>
<div class="container__option">
<h2>3. Subneteo por Subredes</h2>
<label for="IPDecimal-R2">IP: </label>
<input type="text" name="" id="IPDecimal-R2" />
<label for="NumRedes-R2">Numero de Redes: </label>
<input type="text" name="NumRedes-R2" id="NumRedes-R2" />
<table id="TablaEx3"></table>
<input type="button" value="Subnetear" onclick="Ex3();" />
</div>
<div class="container__option">
<h2>Titulo4</h2>
</div>
</div>
<!-- * JavaScript-->
<script src="./JS/script.js"></script>
<script>
// Conversion a Binario
function Ex1() {
// Variables
let IPDecimal = document.getElementById("IPDecimal-R1").value;
// Validacion con RegEx
if (
/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
IPDecimal
)
) {
document.getElementById("IPBinaria-R1").innerHTML =
"IP Binaria: " + IPaBinario(IPDecimal);
} else {
alert("1. IP Invalida");
}
}
// Subneteo por subredes
function Ex3() {
alert("YA, no se, no sirve y ahora odio JS")
// Variables
alert("Hola");
let IP = document.getElementById("IPDecimal-R2").value;
try {
let NRedes = Number(
document.getElementById("NumRedes-R2").value
);
} catch {
return alert("Numero de redes invalido");
}
let Mascara;
let m;
// Eleccion de mascara
if (IP.split(".")[1] == 0) {
Mascara = "255.0.0.0";
m = 12;
} else if (IP.split(".")[2] == 0) {
Mascara = "255.255.0.0";
m = 8;
} else if (IP.split(".")[3] == 0) {
Mascara = "255.255.255.0";
m = 4;
}
let BinMascara = IPaBinario(Mascara);
// Indice donde inician los octetos de Host
let IMascara = BinMascara.indexOf("0");
if (
/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
IP
)
) {
console.log("Pues va bien");
} else {
alert("3. IP Invalida");
}
// Obtencion de n y ajuste de m
let n = 0;
while (true) {
if (2 ** n >= NRedes) {
break;
}
}
m -= n;
let NHost = 2 ** m - 2;
// Obtencion de la nueva mascara en Binario
for (let i = 0; i < n; i++) {
BinMascara[IMascara + i] = "1";
}
// Obtener el salto de red
let Salto =
256 -
Number(
BinarioaDecimal(BinMascara[(IMascara, IMascara + 8)])
);
// Crear tabla
let valor = 0;
for (let i = 0; i < 2 ** n; i++) {
insersion = "<tr>";
terminaion = "</tr>";
let inicial = [IP.subString(0, IP.indexOf(".")) + "."];
let final = [];
document.getElementById("TablaEx3").innerHTML += insersion;
}
}
</script>
</body>
</html>