PyFunceble/check.py
def is_ip_valid(self, ip_to_check=None):
        """
        Check if the given IP is a valid IPv4.

        :param ip_to_check: The IP to test.
        :type ip_to_check: str

        :return: The validity of the IP.
        :rtype: bool

        .. note::
            We only test IPv4 because for now we only them for now.
        """

        # We initate our regex which will match for valid IPv4.
        regex_ipv4 = r"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[0-9]{1,}\/[0-9]{1,})$"  # pylint: disable=line-too-long

        if ip_to_check:
            # An element is localy given.

            # We consider it as the element to test.
            to_test = ip_to_check
        elif self.element:
            # An element is given globally.

            # We consider it as the element to test.
            to_test = self.element
        else:
            # An element is not localy given.

            # We consider the global element to test as the element to test.
            to_test = PyFunceble.INTERN["to_test"]

        # We check if it passes our IPv4 regex.
        # * True: It's a valid IPv4.
        # * False: It's an invalid IPv4.
        return Regex(to_test, regex_ipv4, return_data=False).match()
def is_ip_valid(self, ip_to_check=None):
        """
        Check if the given IP is a valid IPv4.

        :param ip_to_check: The IP to test.
        :type ip_to_check: str

        :return: The validity of the IP.
        :rtype: bool

        .. note::
            We only test IPv4 because for now we only them for now.
        """

        # We initate our regex which will match for valid IPv4.
        regex_ipv4 = r"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[0-9]{1,}\/[0-9]{1,})$"  # pylint: disable=line-too-long

        if ip_to_check:
            # An element is localy given.

            # We consider it as the element to test.
            to_test = ip_to_check
        elif self.element:
            # An element is given globally.

            # We consider it as the element to test.
            to_test = self.element
        else:
            # An element is not localy given.

            # We consider the global element to test as the element to test.
            to_test = PyFunceble.INTERN["to_test"]

        # We check if it passes our IPv4 regex.
        # * True: It's a valid IPv4.
        # * False: It's an invalid IPv4.
        return Regex(to_test, regex_ipv4, return_data=False).match()
def is_ip_valid ( self , ip_to_check = None ) : # We initate our regex which will match for valid IPv4. regex_ipv4 = r"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[0-9]{1,}\/[0-9]{1,})$" # pylint: disable=line-too-long if ip_to_check : # An element is localy given. # We consider it as the element to test. to_test = ip_to_check elif self . element : # An element is given globally. # We consider it as the element to test. to_test = self . element else : # An element is not localy given. # We consider the global element to test as the element to test. to_test = PyFunceble . INTERN [ "to_test" ] # We check if it passes our IPv4 regex. # * True: It's a valid IPv4. # * False: It's an invalid IPv4. return Regex ( to_test , regex_ipv4 , return_data = False ) . match ( )
Check if the given IP is a valid IPv4.

        :param ip_to_check: The IP to test.
        :type ip_to_check: str

        :return: The validity of the IP.
        :rtype: bool

        .. note::
            We only test IPv4 because for now we only them for now.
Check if the given IP is a valid IPv4 .