

Typically, a node will assign IPv6 link-local addresses to interfaces as soon as they have become available. In contrast, IPv6 link-local addresses are used next to other IPv6 addresses. So IPv4 link-local addresses show up when there are no other IPv4 addresses. However, there is a big difference: an IPv4 link-local address is typically assigned to an interface when DHCP fails to supply an address. IPv4 link-local addresses are taken from the prefix 169.254.0.0/16. In practice, only fe80::/64 is used.Īt first glance, IPv6 link-local addresses are similar to IPv4 link-local addresses, which are defined in RFC 3927 (Dynamic Configuration of IPv4 Link-Local Addresses).

IPv6 link-local addresses are defined by RFC 4291 (IPv6 Addressing Architecture) and are covered by the prefix fe80::/10. There have been cases where routers would happily forward packets with a link-local source address. Packets with those addresses are not forwarded by routers. IPv6 link-local addresses are addresses that can be used to communicate with nodes (hosts and routers) on an attached link. In this article, we described how link-local addresses in IPv6, and specifically the '%eth0'-part of link-local addresses, can have an impact on RIPE Atlas measurements. And while this is true for most network operators, if you're a RIPE Atlas system programmer, you can run into interesting situations. Some people say IPv6 is "96 more bits, no magic".

Python 3.3 added a ipaddress module this module does not however include a utility to generate an IPv6 address from a given MAC address.or, how RIPE Atlas measurement data just got a little bit more complex. Sometimes you can express an algorithm in a very concise and readable way, but avoid code-golfing for the sake of compactness.
Automatic ipv6 mac address converter code#
In Python, we usually don't strive for shorter code we aim for readable code. I followed the PEP 8 whitespace recommendations to format the code here whitespace around operators and after commas, for example. # XOR the most significant byte with 0x02, inverting the # Split out the bytes that slot into the IPv6 address # Remove the most common delimiters dots, dashes, etc. In this case, I'd actually split out the various bytes of the MAC address binary value that make up the IPv6 parts, and use str.format() to interpolate those into the IPv6 string.

Use the format() function instead, as it gives you much more control over the output.įor example, format(value, '012x') formats the integer value to a 12-digit hexadecimal (using lowercase digits), padding out the result to the minimum width with leading zeros as needed: > mac_value = 0x237702d2ff9b Note that the purpose of the hex() function is to produce a hexadecimal integer literal (a string that can be used in Python source code), which is why it returns a hex value with the 0x prefix. # Remove/slice the '0x' off the begining from using hex(). # use xor of 02 on the 2nd most significant hex char. # cast the hex string to an base-16 int for math safety. # remove the most common macaddr delimiters, dots, dashes, etc. #!/usr/bin/pythonĬonvert mac addr to ipv6 link local (rfc 4862) I'm using python 2.7, but my Linux distro is soon to switch to 3.x.
