(addr, grpid=None, scope=2)
return inet_ntop(socket.AF_INET6, a)
Generate a Link-Scoped Multicast Address as described in RFC 4489.
    Returned value is in printable notation.

    'addr' parameter specifies the link-local address to use for generating
    Link-scoped multicast address IID.
    
    By default, the function returns a ::/96 prefix (aka last 32 bits of 
    returned address are null). If a group id is provided through 'grpid' 
    parameter, last 32 bits of the address are set to that value (accepted 
    formats : '\x12\x34\x56\x78' or '12345678' or 0x12345678 or 305419896).

    By default, generated address scope is Link-Local (2). That value can 
    be modified by passing a specific 'scope' value as an argument of the
    function. RFC 4489 only authorizes scope values <= 2. Enforcement
    is performed by the function (None will be returned).
    
    If no link-local address can be used to generate the Link-Scoped IPv6
    Multicast address, or if another error occurs, None is returned.
Generate a Link-Scoped Multicast Address as described in RFC 4489.
    Returned value is in printable notation.
Generate a Link - Scoped Multicast Address as described in RFC 4489 . Returned value is in printable notation .
def in6_getLinkScopedMcastAddr(addr, grpid=None, scope=2):
    """
    Generate a Link-Scoped Multicast Address as described in RFC 4489.
    Returned value is in printable notation.

    'addr' parameter specifies the link-local address to use for generating
    Link-scoped multicast address IID.
    
    By default, the function returns a ::/96 prefix (aka last 32 bits of 
    returned address are null). If a group id is provided through 'grpid' 
    parameter, last 32 bits of the address are set to that value (accepted 
    formats : '\x12\x34\x56\x78' or '12345678' or 0x12345678 or 305419896).

    By default, generated address scope is Link-Local (2). That value can 
    be modified by passing a specific 'scope' value as an argument of the
    function. RFC 4489 only authorizes scope values <= 2. Enforcement
    is performed by the function (None will be returned).
    
    If no link-local address can be used to generate the Link-Scoped IPv6
    Multicast address, or if another error occurs, None is returned.
    """
    if not scope in [0, 1, 2]:
        return None    
    try:
        if not in6_islladdr(addr):
            return None
        addr = inet_pton(socket.AF_INET6, addr)
    except:
        warning("in6_getLinkScopedMcastPrefix(): Invalid address provided")
        return None

    iid = addr[8:]

    if grpid is None:
        grpid = '\x00\x00\x00\x00'
    else:
        if type(grpid) is str:
            if len(grpid) == 8:
                try:
                    grpid = int(grpid, 16) & 0xffffffff
                except:
                    warning("in6_getLinkScopedMcastPrefix(): Invalid group id provided")
                    return None
            elif len(grpid) == 4:
                try:
                    grpid = struct.unpack("!I", grpid)[0]
                except:
                    warning("in6_getLinkScopedMcastPrefix(): Invalid group id provided")
                    return None
        grpid = struct.pack("!I", grpid)

    flgscope = struct.pack("B", 0xff & ((0x3 << 4) | scope))
    plen = '\xff'
    res = '\x00'
    a = '\xff' + flgscope + res + plen + iid + grpid

    return inet_ntop(socket.AF_INET6, a)
def in6_getLinkScopedMcastAddr ( addr , grpid = None , scope = 2 ) : if not scope in [ 0 , 1 , 2 ] : return None try : if not in6_islladdr ( addr ) : return None addr = inet_pton ( socket . AF_INET6 , addr ) except : warning ( "in6_getLinkScopedMcastPrefix(): Invalid address provided" ) return None iid = addr [ 8 : ] if grpid is None : grpid = '\x00\x00\x00\x00' else : if type ( grpid ) is str : if len ( grpid ) == 8 : try : grpid = int ( grpid , 16 ) & 0xffffffff except : warning ( "in6_getLinkScopedMcastPrefix(): Invalid group id provided" ) return None elif len ( grpid ) == 4 : try : grpid = struct . unpack ( "!I" , grpid ) [ 0 ] except : warning ( "in6_getLinkScopedMcastPrefix(): Invalid group id provided" ) return None grpid = struct . pack ( "!I" , grpid ) flgscope = struct . pack ( "B" , 0xff & ( ( 0x3 << 4 ) | scope ) ) plen = '\xff' res = '\x00' a = '\xff' + flgscope + res + plen + iid + grpid return inet_ntop ( socket . AF_INET6 , a )