Ejemplo n.º 1
0
    def test_generate_IPs(self):
        """
        Test generate_IPs.
        """
        dummy_list = ['127.0.0.1', '127.0.0.2', '127.0.0.3']
        result = []

        for new_ip in utils.generate_IPs("127.0.0.1-127.0.0.3"):
            result.append(new_ip)

        self.assertEqual(result, dummy_list)

        for new_ip in utils.generate_IPs('128.0.0.1-98.0.0.1'):
            self.assertIsNone(new_ip)
Ejemplo n.º 2
0
    def parse_inbound_IPRule(self):


        try:
            action = int(self.cred['inbound_IPRule']['action'])
            temp_ip_inbound = []
            if len(self.cred['inbound_IPRule']['ip_inbound']):
                list_of_IPs = str(self.cred['inbound_IPRule']['ip_inbound'])
                list_of_IPs = list_of_IPs.split(',')
                for IP in list_of_IPs:
                    if '-' in IP:
                        for new_ip in utils.generate_IPs(IP):
                            if (new_ip not in temp_ip_inbound and
                                utils.check_ip(new_ip)):
                                temp_ip_inbound.append(str(new_ip).strip())
                    elif (utils.check_ip(IP)):
                        if IP not in temp_ip_inbound:
                            temp_ip_inbound.append(str(IP).strip())

            return temp_ip_inbound, action
        except Exception as e:
            self.logger.log(
                "Error: " + str(e),
                logtype="error"
            )
            # Return empty list and block action
            return [], 0