def is_valid_ipv4(instance):
    import ipaddress

    try:
        # accept ipv4 and ipv6
        ipaddress.ip_interface(instance)
        return True
    except ipaddress.AddressValueError:
        return False