Class: Ronin::Nmap::CLI::PortList Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ronin/nmap/cli/port_list.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a list of port numbers and port ranges.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ports) ⇒ PortList

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the port list.

Parameters:

  • ports (Array<Integer, Range>)

    The port numbers and ranges.

Raises:

  • (ArgumentError)

    One of the ports was not an Integer or Range object.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ronin/nmap/cli/port_list.rb', line 50

def initialize(ports)
  @numbers = Set.new
  @ranges  = Set.new

  ports.each do |port|
    case port
    when Integer then @numbers << port
    when Range   then @ranges  << port
    else
      raise(ArgumentError,"port must be an Integer or Range: #{port.inspect}")
    end
  end
end

Instance Attribute Details

#numbersArray<Integer> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Port numbers.

Returns:

  • (Array<Integer>)


34
35
36
# File 'lib/ronin/nmap/cli/port_list.rb', line 34

def numbers
  @numbers
end

#rangesArray<Range> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Port ranges.

Returns:

  • (Array<Range>)


39
40
41
# File 'lib/ronin/nmap/cli/port_list.rb', line 39

def ranges
  @ranges
end

Class Method Details

.parse(ports) ⇒ PortList

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses the port list.

Parameters:

  • ports (String)

    The port list to parse.

Returns:

  • (PortList)

    The port numbers and port ranges.



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ronin/nmap/cli/port_list.rb', line 73

def self.parse(ports)
  new(
    ports.split(',').map do |port|
      if port.include?('-')
        start, stop = port.split('-',2)

        Range.new(start.to_i,stop.to_i)
      else
        port.to_i
      end
    end
  )
end

Instance Method Details

#include?(port) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines if the port is in the port list.

Parameters:

  • port (Integer)

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/ronin/nmap/cli/port_list.rb', line 94

def include?(port)
  @numbers.include?(port) ||
    @ranges.any? { |range| range.include?(port) }
end