-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipv6subnet.html
107 lines (94 loc) · 4.08 KB
/
ipv6subnet.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="js/ip-address.js"></script>
<title>Tools | IPv6 subnet calculator</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
</head>
<body>
<ul id="menu">
<li><a href="index.html"><i class="fas fa-home"></i><p>Home</p></a></li>
<li><a href="password.html"><i class="fas fa-key"></i><p>Password generator</p></a></li>
<li><a href="ipRangeToCidr.html"><i class="fas fa-network-wired"></i><p>IPv4 range to subnet</p></a></li>
<li><a href="ipv4subnet.html"><i class="fas fa-calculator"></i><p>IPv4 subnet calculator</p></a></li>
<li><a href="ipv6subnet.html"><i class="fas fa-calculator"></i><p>IPv6 subnet calculator</p></a></li>
<li><a href="ipv4convert.html"><i class="fas fa-exchange"></i><p>IPv4 converter</p></a></li>
<li><a href="unixtime.html"><i class="fas fa-clock"></i><p>Unix time converter</p></a></li>
<li><a href="domain.html"><i class="fas fa-search"></i><p>Domain lookup</p></a></li>
</ul>
<div id="content">
<div id="hero">
<h1>IPv6 Subnet Calculator</h1>
</div>
<div class="break"></div>
<div class="options">
<div>
<input class="main" id="subnetField" placeholder="2400:cb00::/32" oninput="convertSubnet()">
</div>
</div>
<div class="break"></div>
<div class="options">
<div>
<label for="displaySelect">Display:</label>
<select id="displaySelect" value="long" oninput="convertSubnet()">
<option value="long">Long</option>
<option value="short">Short</option>
</select>
</div>
</div>
<div class="buttons">
<button>Calculate</button>
</div>
<div class="results-ipsubnet">
<h4 id="errorField"></h4>
<div class="bvals"><p>CIDR:</p><p id="cidr">...</p></div>
<div class="bvals"><p>Address:</p><p id="address">...</p></div>
<div class="bvals"><p>Range start:</p><p id="rangeStart">...</p></div>
<div class="bvals"><p>Range end:</p><p id="rangeEnd">...</p></div>
<div class="bvals"><p>Usable:</p><p id="usable">...</p></div>
<div class="bvals"><p>Bits:</p><p id="bits">...</p></div>
</div>
</div>
<script>
const errorField = document.getElementById("errorField");
convertSubnet();
function convertSubnet() {
const subnetField = document.getElementById("subnetField");
const displaySelect = document.getElementById("displaySelect");
const long = displaySelect.value === "long";
const cidr = document.getElementById("cidr");
const address = document.getElementById("address");
const rangeStart = document.getElementById("rangeStart");
const rangeEnd = document.getElementById("rangeEnd");
const bits = document.getElementById("bits");
const usable = document.getElementById("usable");
if (!subnetField.value || !subnetField.value.split("/")[1]) return;
let subnet;
try {
subnet = new ip.Address6(subnetField.value);
} catch {
errorField.innerText = "Invalid subnet mask";
cidr.innerText = "";
address.innerText = "";
rangeStart.innerText = "";
rangeEnd.innerText = "";
bits.innerText = "";
usable.innerText = "";
return;
}
cidr.innerText = displayIp(subnet, long) + "/" + subnet.subnetMask;
address.innerText = displayIp(subnet, long);
rangeStart.innerText = displayIp(subnet.startAddress(), long);
rangeEnd.innerText = displayIp(subnet.endAddress(), long);
bits.innerText = subnet.subnetMask;
usable.innerText = subnet.possibleSubnets();
}
function displayIp(address, long) {
return long ? address.canonicalForm() : address.correctForm();
}
</script>
</body>
</html>