-
-
-def valid_ipv4(ip):
- """Check if IP address has the correct IPv4 address format.
-
- :param ip: IP address.
- :type ip: str
- :return: True in case of correct IPv4 address format,
- otherwise return False.
- :rtype: bool
- """
- try:
- ipaddress.IPv4Address(ip)
- return True
- except (AttributeError, ipaddress.AddressValueError):
- return False
-
-
-def valid_ipv6(ip):
- """Check if IP address has the correct IPv6 address format.
-
- :param ip: IP address.
- :type ip: str
- :return: True in case of correct IPv6 address format,
- otherwise return False.
- :rtype: bool
- """
- try:
- ipaddress.IPv6Address(ip)
- return True
- except (AttributeError, ipaddress.AddressValueError):
- return False