#!/usr/bin/python3
"""validate-ipaddress - check the first argument to see if it is a valid IP
address (IPv4 or IPv6).  Returns 0 on success, 1 if the IP address is not
valid, 2 if the IP address argument is missing, and 3 if an unexpected error
is encountered.  No error message is emitted if the IP address is invalid.
"""

import ipaddress
import sys

try:
    ipaddress.ip_address(sys.argv[1])
except ValueError:
    exit_val = 1
except IndexError:
    print("Missing IP address argument", file=sys.stderr)
    exit_val = 2
except Exception as exc:
    print(f"Error processing IP address {sys.argv[1]}: {exc}", file=sys.stderr)
    exit_val = 3
else:
    exit_val = 0
sys.exit(exit_val)
