import socket


def ipv6_to_bytes(addr):
    """ Convert Ipv6 address to a bytes. """
    if (isinstance(addr, bytes)):
        addr = addr.decode()
    return bytearray(socket.inet_pton(socket.AF_INET6, addr))