-
-
Save zed/89ece9515a748afd6798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Convert ip address to RFC3056 IPv6 6to4 address.""" | |
import binascii | |
import ipaddress | |
ip4str = input("Enter IPv4 (e.g., 9.254.253.252):") | |
ip4 = ipaddress.IPv4Address(ip4str) | |
h = binascii.hexlify(ip4.packed).decode() | |
ip6 = ipaddress.IPv6Address("2002:" + h[:4] + ":" + h[4:] + "::") | |
print() | |
print("ip4 address: ", ip4) | |
print("Integer (decimal): ", int(ip4)) | |
print("Integer (binary): ", bin(int(ip4))[2:]) | |
print("Ingeger (hexadecimal): ", h) | |
assert len(h) == 8 | |
print("6to4 address: ", ip6) | |
assert ip6.sixtofour == ip4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment