Spaces:
Running
Running
button Calculate IPs is not calculating, not funtioning
Browse files
script.js
CHANGED
|
@@ -103,7 +103,7 @@ l2lBtn.addEventListener('click', function() {
|
|
| 103 |
// Copy table to clipboard
|
| 104 |
const copyTableBtn = document.getElementById('copyTableBtn');
|
| 105 |
copyTableBtn.addEventListener('click', function() {
|
| 106 |
-
let tableText = 'Type\tIP Address\tSubnet Mask\n';
|
| 107 |
const rows = ipTableBody.querySelectorAll('tr');
|
| 108 |
|
| 109 |
rows.forEach(row => {
|
|
@@ -119,9 +119,68 @@ let tableText = 'Type\tIP Address\tSubnet Mask\n';
|
|
| 119 |
feather.replace();
|
| 120 |
}, 2000);
|
| 121 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
}
|
|
|
|
| 123 |
// Copy email to clipboard
|
| 124 |
-
|
| 125 |
const textToCopy = emailOutput.textContent;
|
| 126 |
navigator.clipboard.writeText(textToCopy).then(() => {
|
| 127 |
const originalText = copyBtn.innerHTML;
|
|
|
|
| 103 |
// Copy table to clipboard
|
| 104 |
const copyTableBtn = document.getElementById('copyTableBtn');
|
| 105 |
copyTableBtn.addEventListener('click', function() {
|
| 106 |
+
let tableText = 'Type\tIP Address\tSubnet Mask\n';
|
| 107 |
const rows = ipTableBody.querySelectorAll('tr');
|
| 108 |
|
| 109 |
rows.forEach(row => {
|
|
|
|
| 119 |
feather.replace();
|
| 120 |
}, 2000);
|
| 121 |
});
|
| 122 |
+
});
|
| 123 |
+
// Make sure calculate button works immediately
|
| 124 |
+
calculateBtn.addEventListener('click', calculateIPs);
|
| 125 |
+
|
| 126 |
+
function calculateIPs() {
|
| 127 |
+
const ipRange = ipRangeInput.value.trim();
|
| 128 |
+
if (!ipRange) {
|
| 129 |
+
alert('Please enter a valid IP range (e.g., 190.220.1.216/29)');
|
| 130 |
+
return;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
try {
|
| 134 |
+
const [baseIp, cidr] = ipRange.split('/');
|
| 135 |
+
const cidrNumber = parseInt(cidr);
|
| 136 |
+
|
| 137 |
+
if (cidrNumber < 0 || cidrNumber > 32) {
|
| 138 |
+
throw new Error('Invalid CIDR');
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
const subnetMask = calculateSubnetMask(cidrNumber);
|
| 142 |
+
const ipParts = baseIp.split('.').map(Number);
|
| 143 |
+
const networkAddress = calculateNetworkAddress(ipParts, cidrNumber);
|
| 144 |
+
const broadcastAddress = calculateBroadcastAddress(networkAddress, cidrNumber);
|
| 145 |
+
|
| 146 |
+
// Clear previous results
|
| 147 |
+
ipTableBody.innerHTML = '';
|
| 148 |
+
|
| 149 |
+
// Add network address row
|
| 150 |
+
addTableRow('RED LAN', formatIp(networkAddress), subnetMask);
|
| 151 |
+
|
| 152 |
+
// Calculate usable IPs (network +1 to broadcast -1)
|
| 153 |
+
const startIp = [...networkAddress];
|
| 154 |
+
incrementIp(startIp);
|
| 155 |
+
|
| 156 |
+
// Calculate the number of usable hosts
|
| 157 |
+
const usableHosts = Math.pow(2, 32 - cidrNumber) - 2;
|
| 158 |
+
|
| 159 |
+
// Add gateway (first usable IP)
|
| 160 |
+
addTableRow('GATEWAY', formatIp(startIp), subnetMask);
|
| 161 |
+
|
| 162 |
+
// Increment for next IP
|
| 163 |
+
incrementIp(startIp);
|
| 164 |
+
|
| 165 |
+
// Add available client IPs
|
| 166 |
+
for (let i = 0; i < usableHosts - 1; i++) {
|
| 167 |
+
if (formatIp(startIp) === formatIp(broadcastAddress)) break;
|
| 168 |
+
addTableRow('DISPONIBLE CLIENTE', formatIp(startIp), subnetMask);
|
| 169 |
+
incrementIp(startIp);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
// Add broadcast address
|
| 173 |
+
addTableRow('BROADCAST', formatIp(broadcastAddress), subnetMask);
|
| 174 |
+
|
| 175 |
+
ipTableContainer.classList.remove('hidden');
|
| 176 |
+
} catch (error) {
|
| 177 |
+
alert('Invalid IP range format. Please use format like 190.220.1.216/29');
|
| 178 |
+
console.error(error);
|
| 179 |
+
}
|
| 180 |
}
|
| 181 |
+
|
| 182 |
// Copy email to clipboard
|
| 183 |
+
copyBtn.addEventListener('click', function() {
|
| 184 |
const textToCopy = emailOutput.textContent;
|
| 185 |
navigator.clipboard.writeText(textToCopy).then(() => {
|
| 186 |
const originalText = copyBtn.innerHTML;
|