import socket


def ip_sort_key(ip_address):
    """Get a sort key for an IPv4 or IPv6 address"""
    if ':' in ip_address:
        # IPv6
        return b'6' + socket.inet_pton(socket.AF_INET6, ip_address)
    # IPv4
    return b'4' + socket.inet_aton(ip_address)