-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipv4convert.html
94 lines (84 loc) · 3.51 KB
/
ipv4convert.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
<!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 | IPv4 convertor</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>IPv4 Converter</h1>
</div>
<div class="break"></div>
<div class="options">
<div>
<input class="main" id="ipField" placeholder="178.18.0.1" oninput="convertIp()" />
</div>
</div>
<div class="buttons">
<button>Convert</button>
</div>
<div class="results-ipsubnet">
<h4 id="errorField"></h4>
<div class="bvals"><p>IPv4:</p><p id="ipv4">...</p></div>
<div class="bvals"><p>IPv6 (short):</p><p id="ipv6s">...</p></div>
<div class="bvals"><p>IPv6 (long):</p><p id="ipv6l">...</p></div>
<div class="bvals"><p>Integer:</p><p id="ipi">...</p></div>
<div class="bvals"><p>Hex:</p><p id="iph">...</p></div>
</div>
</div>
<script>
const errorField = document.getElementById("errorField");
convertIp();
function convertIp() {
errorField.innerText = "";
const ipField = document.getElementById("ipField");
const ipv4 = document.getElementById("ipv4");
const ipv6s = document.getElementById("ipv6s");
const ipv6l = document.getElementById("ipv6l");
const ipi = document.getElementById("ipi");
const iph = document.getElementById("iph");
if (!ipField.value) return;
if (!ipField.value.split(".")[3]) return;
let address;
try {
// don't question it
if (!!ipField.value.split("/")[1]) throw Error();
address = new ip.Address4(ipField.value);
} catch {
errorField.innerText = "Invalid IP address";
ipv4.innerText = "";
ipv6s.innerText = "";
ipv6l.innerText = "";
ipi.innerText = "";
iph.innerText = "";
return;
}
ipv4.innerText = address.address;
ipv6s.innerText = ip.Address6.fromAddress4(
address.address
).correctForm();
ipv6l.innerText = ip.Address6.fromAddress4(
address.address
).canonicalForm();
ipi.innerText = Number(address.bigInteger());
// original method give a number in a format like 00:00:00:00 which would be then converted to 0x00000000
iph.innerText = "0x" + address.toHex().toUpperCase().replace(/:+/g, "");
}
</script>
</body>
</html>