Skip to content

Instantly share code, notes, and snippets.

@veltlion
veltlion / mac_to_ipv6.bash
Created January 16, 2023 04:05 — forked from mej/mac_to_ipv6.bash
[BASH] Function to convert MAC address to IPv6 link-local address
mac_to_ipv6() {
local HWADDR="$1" IFACE="$2"
local -a OCTETS
local IPV6ADDR
if [[ -z "$IFACE" ]]; then
IFACE=$(ip route | grep ^default | sed 's/^.* dev //')
fi
OCTETS=( ${HWADDR//:/\ } )
OCTETS[0]=$(printf %02x $((16#${OCTETS[0]}+0x02)))