Helper function to convert an address into an IPAddress object.
    Canonicalizes IPv6-mapped (or compatible) IPv4 addresses into IPv4
    addresses.  Returns None if the address cannot be parsed.

def _parse_ip(addr):
    """
    Helper function to convert an address into an IPAddress object.
    Canonicalizes IPv6-mapped (or compatible) IPv4 addresses into IPv4
    addresses.  Returns None if the address cannot be parsed.
    """

    # Parse the IP address
    try:
        address = netaddr.IPAddress(addr.strip())
    except (ValueError, netaddr.AddrFormatError):
        return None

    # Canonicalize it, if possible
    if address.version == 6:
        try:
            return address.ipv4()
        except netaddr.AddrConversionError:
            pass

    return address