-
Notifications
You must be signed in to change notification settings - Fork 0
/
IP Converter.html
129 lines (118 loc) · 5.26 KB
/
IP Converter.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>IP Converter</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;300;400;500;600;700;900&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Poppins', sans-serif;
}
.numbers{
font-family: 'JetBrains Mono', monospace;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand">Subnet Analysis</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item ">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="IP%20Converter.html">IP Converter</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Other.html">Other</a>
</li>
</ul>
</div>
</nav>
<div class="container mt-5">
<h1 class="mb-4">IP Converter</h1>
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="card">
<div class="card-header">
<h2 class="mb-0">Binary to Decimal</h2>
</div>
<div class="card-body">
<div class="form-group">
<label for="binaryIP">Enter Binary IP Address:</label>
<input type="text" class="numbers form-control" id="binaryIP" placeholder="Enter binary IP address...">
</div>
<button class="btn btn-primary btn-block" onclick="convertBinaryToDecimal()">Convert</button>
<p class="mt-3">Decimal Dotted Notation: <span class="numbers" id="decimalResult"></span></p>
<button class="btn btn-success btn-block" onclick="copyToClipboard('decimalResult')">Copy to Clipboard</button>
</div>
</div>
</div>
<div class="col-md-6 col-sm-12">
<div class="card">
<div class="card-header">
<h2 class="mb-0">Decimal to Binary</h2>
</div>
<div class="card-body">
<div class="form-group">
<label for="decimalIP">Enter Decimal IP Address:</label>
<input type="text" class="numbers form-control" id="decimalIP"
placeholder="Enter decimal IP address...">
</div>
<button class="btn btn-primary btn-block" onclick="convertDecimalToBinary()">Convert</button>
<p class="mt-3">Binary Dotted Notation: <span class="numbers" id="binaryResult"></span></p>
<button class="btn btn-success btn-block" onclick="copyToClipboard('binaryResult')">Copy to Clipboard</button>
</div>
</div>
</div>
</div>
</div>
<script>
function convertBinaryToDecimal() {
var binaryIP = document.getElementById("binaryIP").value;
var binaryGroups = binaryIP.split(".");
var decimalGroups = [];
for (var i = 0; i < binaryGroups.length; i++) {
var decimal = parseInt(binaryGroups[i], 2);
decimalGroups.push(decimal);
}
var decimalDottedNotation = decimalGroups.join(".");
document.getElementById("decimalResult").innerHTML = decimalDottedNotation;
}
function convertDecimalToBinary() {
var decimalIP = document.getElementById("decimalIP").value;
var decimalGroups = decimalIP.split(".");
var binaryGroups = [];
for (var i = 0; i < decimalGroups.length; i++) {
var binary = parseInt(decimalGroups[i]).toString(2).padStart(8, '0');
binaryGroups.push(binary);
}
var binaryDottedNotation = binaryGroups.join(".");
document.getElementById("binaryResult").innerHTML = binaryDottedNotation;
}
function copyToClipboard(elementId) {
var element = document.getElementById(elementId);
var range = document.createRange();
range.selectNode(element);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="script.js"></script>
</body>
</html>