import socket
import struct


def ipv6_to_long(ip):
    """Return the IPv6 address string as a long

    >>> ipv6_to_long("2001:db8::1")
    42540766411282592856903984951653826561L
    >>> ipv6_to_long("::1")
    1L
    """
    ip_bytes_n = socket.inet_pton(socket.AF_INET6, ip)
    ip_parts = struct.unpack('!QQ', ip_bytes_n)
    return 2**64 * ip_parts[0] + ip_parts[1]