import socket


def ip_sort_key(ip):
	"""
	Key used in sorting ipv4 and ipv6 addresses
	"""
	try:
		return socket.inet_pton(socket.AF_INET6, ip)
	except socket.error:
		return socket.inet_pton(socket.AF_INET, ip)