Class: Masscan::Command::PortList Private

Inherits:
CommandMapper::Types::List
  • Object
show all
Defined in:
lib/masscan/command.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 the type for the -p,--ports option.

Since:

  • 0.2.0

Constant Summary collapse

PORT_RANGE_REGEXP =

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

Regular expression for validating a port or port range.

Since:

  • 0.2.0

PortRange::PORT_RANGE_REGEXP
REGEXP =

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

Regular expression that validates port list String values.

Since:

  • 0.2.0

/\A(?:(?:U:)?#{PORT_RANGE_REGEXP})(?:,(?:U:)?#{PORT_RANGE_REGEXP})*\z/

Instance Method Summary collapse

Constructor Details

#initializePortList

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.

Initializes the port list type.

Since:

  • 0.2.0



246
247
248
# File 'lib/masscan/command.rb', line 246

def initialize
  super(type: PortRange.new)
end

Instance Method Details

#format(value) ⇒ String

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.

Formats a port list value into a String.

Parameters:

  • value (Array<String, Integer, Range>, Range<Integer,Integer>, String, #to_s)

    The port list value to format.

Returns:

  • (String)

    The formatted port list string.

Since:

  • 0.2.0



284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/masscan/command.rb', line 284

def format(value)
  case value
  when Range
    # format an individual port range
    @type.format(value)
  when String
    # pass strings directly through
    value
  else
    super(value)
  end
end

#validate(value) ⇒ true, (false, String)

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.

Validates a given value.

Parameters:

  • value (Array, Range, String, Object)

    The port list value.

Returns:

  • (true, (false, String))

    Returns true if the value is valid, or false and a validation error message if the value is not compatible.

Since:

  • 0.2.0



260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/masscan/command.rb', line 260

def validate(value)
  case value
  when Range
    @type.validate(value)
  when String
    unless value =~ REGEXP
      return [false, "not a valid port list (#{value.inspect})"]
    end

    return true
  else
    super(value)
  end
end