Class: MetasploitDataModels::Search::Operator::Port::List

Inherits:
Metasploit::Model::Search::Operator::Group::Union
  • Object
show all
Defined in:
app/models/metasploit_data_models/search/operator/port/list.rb

Overview

Searches for a network port attribute. Ports can be given as a single number or range of numbers and either or both forms can be combined into a comma separated list. Individual port numbers are validated to be greater than 0 and

Constant Summary collapse

SEPARATOR =

Separates port number and/or port ranges

','

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributeSymbol Also known as: name

Defaults to :port.

Returns:

  • (Symbol)

19
# File 'app/models/metasploit_data_models/search/operator/port/list.rb', line 19

attr_writer :attribute

Class Method Details

.operator_nameString

Note:

Can't be called name because it would alias Class#name

Name of this operator.

Returns:

  • (String)

    'port_list'


30
31
32
# File 'app/models/metasploit_data_models/search/operator/port/list.rb', line 30

def self.operator_name
  'port_list'
end

Instance Method Details

#children(formatted_value) ⇒ Array<Metasploit::Model::Search::Operation::Base]

Turns {#attribute}:<number>,<range> into the union of port and port searches.

Parameters:

  • formatted_value (String)

    comma separated list of port numbers and ranges.

Returns:

  • (Array<Metasploit::Model::Search::Operation::Base])

    Array<Metasploit::Model::Search::Operation::Base]


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/metasploit_data_models/search/operator/port/list.rb', line 49

def children(formatted_value)
  separated_formatted_values = formatted_value.split(SEPARATOR)

  separated_formatted_values.collect { |separated_formatted_value|
    operation_class = MetasploitDataModels::Search::Operation::Port::Number

    if separated_formatted_value.include? MetasploitDataModels::Search::Operation::Range::SEPARATOR
      operation_class = MetasploitDataModels::Search::Operation::Port::Range
    end

    operation_class.new(
        value: separated_formatted_value,
        operator: self
    )
  }
end