Class: Nmap::Command::PortRange Private

Inherits:
Port
  • Object
show all
Defined in:
lib/nmap/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.

API:

  • private

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.

API:

  • private

/(?:#{PORT_NUMBER_REGEXP})?-(?:#{PORT_NUMBER_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.

API:

  • private

/\A#{PORT_RANGE_REGEXP}\z/

Constants inherited from Port

Nmap::Command::Port::PORT_NUMBER_REGEXP, Nmap::Command::Port::PORT_REGEXP, Nmap::Command::Port::SERVICE_NAME_REGEXP

Instance Method Summary collapse

Methods inherited from Port

#initialize

Constructor Details

This class inherits a constructor from Nmap::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:

  • The port or port range value to format.

Returns:

  • The formatted port or port range.

API:

  • private



318
319
320
321
322
323
324
325
# File 'lib/nmap/command.rb', line 318

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:

  • The port or port range value to validate.

Returns:

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

API:

  • private



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/nmap/command.rb', line 282

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
    if value =~ REGEXP
      return true
    else
      return [false, "must be a valid port number, port range, or service name (#{value.inspect})"]
    end
  else
    super(value)
  end
end