Class: Ronin::Nmap::CLI::PortList Private
- Inherits:
-
Object
- Object
- Ronin::Nmap::CLI::PortList
- 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
-
#numbers ⇒ Array<Integer>
readonly
private
Port numbers.
-
#ranges ⇒ Array<Range>
readonly
private
Port ranges.
Class Method Summary collapse
-
.parse(ports) ⇒ PortList
private
Parses the port list.
Instance Method Summary collapse
-
#include?(port) ⇒ Boolean
private
Determines if the port is in the port list.
-
#initialize(ports) ⇒ PortList
constructor
private
Initialize the port list.
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.
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
#numbers ⇒ Array<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.
34 35 36 |
# File 'lib/ronin/nmap/cli/port_list.rb', line 34 def numbers @numbers end |
#ranges ⇒ Array<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.
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.
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.
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 |