Ejemplo n.º 1
0
    def test_error_reporting(self):
        with self.assertRaises(ValueError):
            parseIntSet("80-90 , tree", True)

        result = parseIntSet("80-81, tree")
        self.assertEqual(len(result), 2)
        self.assertEqual(result, set([80, 81]))
Ejemplo n.º 2
0
    def to_python(self, value, session_key=None):
        Field.to_python(self, value, session_key)

        if value is None:
            return None

        try:
            ports_list = parseIntSet(value, True)
        except ValueError:
            raise FieldValidationException("The value of '%s' for the '%s' parameter is not a valid list" % (str(value), self.name))

        return ports_list
    def __init__(self,
                 dest=None,
                 ports=None,
                 index=None,
                 host=None,
                 timeout=5):
        SearchCommand.__init__(self,
                               run_in_preview=False,
                               logger_name="portscan_search_command")

        self.dest = dest

        # Use the host argument if someone provided that instead (since that is the older argument supported by some of the other commands)
        if self.dest is None and host is not None:
            self.dest = host

        self.index = index

        if ports is None:
            raise ValueError('The list of ports to scan must be provided')

        try:
            parseIntSet(ports, True)
        except ValueError:
            raise ValueError('The list of ports to scan is invalid')

        self.ports = ports

        try:
            self.timeout = int(timeout)
        except ValueError:
            raise ValueError('The must be a valid integer')

        if self.timeout <= 0:
            raise ValueError(
                'The must be a valid positive integer (greater than zero)')

        self.logger.info("Port scan running")
Ejemplo n.º 4
0
    def test_extra_spaces(self):
        result = parseIntSet(" 80-90 , 8443 ")

        self.assertEqual(len(result), 12)
        self.assertEqual(
            result, set([80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 8443]))
Ejemplo n.º 5
0
    def test_duplicates(self):
        result = parseIntSet("80-90,89")
        self.assertEqual(result,
                         set([80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90]))

        self.assertEqual(len(result), 11)
Ejemplo n.º 6
0
    def test_single(self):
        result = parseIntSet("80")

        self.assertEqual(len(result), 1)
        self.assertEqual(result, set([80]))