Created
September 11, 2013 08:59
-
-
Save bp-/6521070 to your computer and use it in GitHub Desktop.
Converts a mac address to the corresponding EUI 64 IPv6.
This file contains hidden or 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
from netaddr import * | |
def mac2ipv6( mac, prefix ): | |
mac = EUI(mac).eui64() | |
bits = list(str(mac.bits())) | |
bits[6] = "1" | |
bits = "".join(bits) | |
bytes = bits.split("-"); | |
bytes = [''.join([bytes[0], bytes[1]]), ''.join([bytes[2], bytes[3]]), ''.join([bytes[4], bytes[5]]), ''.join([bytes[6], bytes[7]]) ] | |
ipv6 = [prefix]; | |
for byte in bytes: | |
ipv6.append(hex(int(byte, 2))[2:6]) | |
return ":".join(ipv6) | |
prefix = "2001:4001:dead:beef" | |
mac = "da:a0:b1:c2:d3:e4" | |
print(mac2ipv6(mac, prefix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment