Skip to content

Instantly share code, notes, and snippets.

@pallas
Created August 9, 2019 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pallas/d0783ab31631875fd714c7fd5a966df6 to your computer and use it in GitHub Desktop.
Save pallas/d0783ab31631875fd714c7fd5a966df6 to your computer and use it in GitHub Desktop.
Inject MAC address into IPv6 Network
# SPDX-License-Identifier: Unlicense
from ipaddress import IPv6Network
from binascii import unhexlify
network = IPv6Network("2001:DB8::/32")
mac = "12:34:56:78:9a:bc"
mac_bytes = b''.join(map(unhexlify, mac.split(':')))
address = network[int.from_bytes(mac_bytes, byteorder='big')]
print(network, mac, mac_bytes, address)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment