import socket


def canonv4(text):
    """canonicalize an IPv4 address"""
    if text is None:
        return None
    try:
        addr = socket.inet_pton(socket.AF_INET, text)
        return socket.inet_ntop(socket.AF_INET, addr)
    except socket.error:
        #print 'canonv4 failed on', text
        return None