Created
December 5, 2025 08:54
-
-
Save phoenixthrush/30c7852bb3fe8193126c0ae4c380406d to your computer and use it in GitHub Desktop.
A command-line tool that converts a MAC address into its IPv6 link-local address by building the EUI-64 interface ID, inserting FF:FE, flipping the UL-bit, and outputting both full and compressed LLA formats. #IPv6 #EUI64 #Networking
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 ipaddress import ip_address | |
| def get_list_colon_sep(lst): | |
| conc_lst = "".join(lst) | |
| colon_sep_lst = "" | |
| for i in range(0, len(conc_lst), 2): | |
| colon_sep_lst += conc_lst[i] + conc_lst[i + 1] + ":" | |
| colon_sep_lst = colon_sep_lst[:-1] | |
| return colon_sep_lst | |
| MAC_ADDRESS = input("Enter MAC address: ") | |
| if MAC_ADDRESS == "": | |
| MAC_ADDRESS = "aa:bb:cc:dd:ee:ff" | |
| print(f"{'=' * 55}\nMAC\t\t{MAC_ADDRESS}") | |
| # insert FFFE | |
| mac_split = MAC_ADDRESS.split(":") | |
| mac_split.insert(3, "ff") | |
| mac_split.insert(4, "fe") | |
| interface_id = [] | |
| for i in range(0, len(mac_split), 2): | |
| interface_id.append(f"{mac_split[i]}{mac_split[i + 1]}") | |
| print(f"Interface ID:\t{get_list_colon_sep(interface_id)}") | |
| # flip UL-Bit | |
| first_byte = interface_id[0][:2] | |
| ul_bits = bin(int(first_byte, 16))[2:].zfill(len(first_byte) * 4) | |
| # print(ul_bits) | |
| ul_bits_flip = f"{ul_bits[:6]}{'1' if ul_bits[6] == '0' else '0'}{ul_bits[7:]}" | |
| ul_byte_flip_hex = hex(int(ul_bits_flip, 2))[2:] | |
| # print(f"UL-Byte:\t\t{ul_byte_flip_hex}") | |
| eui_id = interface_id | |
| eui_id[0] = f"{ul_byte_flip_hex}{interface_id[0][2:]}" | |
| print(f"EUI-64-I/F ID:\t{get_list_colon_sep(eui_id)}") | |
| lla = f"fe80:0000:0000:0000:{':'.join(eui_id)}" | |
| print(f"LLA:\t\t{lla}") | |
| print(f"LLA (comp.):\t{ip_address(lla)}\n{'=' * 55}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment