Class: Masscan::Command::PortRange Private

Inherits:
Port
  • 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 a port range.

Since:

  • 0.3.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 to validate either a port or a port range.

Since:

  • 0.3.0

/#{PORT_REGEXP}-#{PORT_REGEXP}|#{PORT_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 to validate either a port or a port range.

Since:

  • 0.3.0

/\A#{PORT_RANGE_REGEXP}\z/

Constants inherited from Port

Masscan::Command::Port::PORT_REGEXP

Instance Method Summary collapse

Methods inherited from Port

#initialize

Constructor Details

This class inherits a constructor from Masscan::Command::Port

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 the given port or port range value.

Parameters:

  • value (Range, Integer, String)

    The port or port range value to format.

Returns:

  • (String)

    The formatted port or port range.

Since:

  • 0.3.0



219
220
221
222
223
224
225
226
# File 'lib/masscan/command.rb', line 219

def format(value)
  case value
  when Range
    "#{value.begin}-#{value.end}"
  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 the given port or port range value.

Parameters:

  • value (Object)

    The port or port range value to validate.

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.3.0



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/masscan/command.rb', line 183

def validate(value)
  case value
  when Range
    valid, message = super(value.begin)

    unless valid
      return [valid, message]
    end

    valid, message = super(value.end)

    unless valid
      return [valid, message]
    end

    return true
  when String
    unless value =~ REGEXP
      return [false, "must be a valid port range or port number (#{value.inspect})"]
    end

    return true
  else
    super(value)
  end
end