/** * Extracts /48, /56, and /64 prefixes from an IPv6 address * @param {string} ipv6 - The IPv6 address in standard or compressed format * @returns {Object} Object containing the /48, /56, and /64 prefixes */ function extractIPv6Prefixes(ipv6) { // Expand the compressed IPv6 address let expandedIPv6 = expandIPv6(ipv6); // Split the address into groups const groups = expandedIPv6.split(':'); // Extract prefixes const prefix48 = groups.slice(0, 3).join(':'); const prefix56 = groups.slice(0, 3).join(':') + ':' + groups[3].substring(0, 1); const prefix64 = groups.slice(0, 4).join(':'); return { prefix48: prefix48, prefix56: prefix56, prefix64: prefix64, expanded: expandedIPv6 }; } /** * Expands a compressed IPv6 address to its full form * @param {string} ipv6 - The IPv6 address, possibly in compressed format * @returns {string} The expanded IPv6 address */ function expandIPv6(ipv6) { // Handle double colon expansion if (ipv6.includes('::')) { const parts = ipv6.split('::'); const left = parts[0] ? parts[0].split(':') : []; const right = parts[1] ? parts[1].split(':') : []; const missing = 8 - left.length - right.length; // Create the expanded middle section const middle = Array(missing).fill('0000'); // Join all parts together const full = [...left, ...middle, ...right]; // Ensure each part is properly padded return full.map(part => part.padStart(4, '0')).join(':'); } // If no compression, just ensure each part is padded return ipv6.split(':').map(part => part.padStart(4, '0')).join(':'); }