def is_valid_ip ( ip_address ) : valid = True try : socket . inet_aton ( ip_address . strip ( ) ) except : valid = False return valid
python ipaddress how to test for errors
Check Validity of an IP address
def is_valid_ip(ip_address):
    """
    Check Validity of an IP address
    """
    valid = True
    try:
        socket.inet_aton(ip_address.strip())
    except:
        valid = False
    return valid