🛠️ToolsShed

Expander/Kompresor IPv6

Perluas alamat IPv6 yang dikompresi ke notasi lengkap atau kompres ke bentuk terpendek.

Pertanyaan yang Sering Diajukan

Implementasi Kode

import ipaddress

def expand_ipv6(addr: str) -> str:
    """Expand compressed IPv6 to full form."""
    return ipaddress.ip_address(addr).exploded

def compress_ipv6(addr: str) -> str:
    """Compress full IPv6 to shortest form."""
    return ipaddress.ip_address(addr).compressed

examples = [
    "2001:db8::1",
    "::1",
    "fe80::1",
    "2001:0db8:0000:0000:0000:0000:0000:0001",
    "::ffff:192.168.1.1",  # IPv4-mapped IPv6
]

for addr in examples:
    expanded  = expand_ipv6(addr)
    compressed = compress_ipv6(expanded)
    print(f"Input:      {addr}")
    print(f"Expanded:   {expanded}")
    print(f"Compressed: {compressed}")
    print()

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.