import socket
import fcntl
import struct


def get_mac_address(ifname: str) -> str:
    """
    Uses the Linux SIOCGIFHWADDR ioctl to find the HW/mac address associated with a network interface, given the name of
    that interface
    :param ifname: the interface to find the HW/max address associated with
    :return: the HW/mac address associated with the given interface
    """
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    info = fcntl.ioctl(
        s.fileno(),
        0x8927,  # SIOCGIFHWADDR
        struct.pack("256s", bytes(ifname, "utf-8")[:15]),
    )
    return ":".join("%02x" % b for b in info[18:24])