Class: Nmap::Command::Port Private

Inherits:
CommandMapper::Types::Num
  • 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 number.

Direct Known Subclasses

PortRange

Constant Summary collapse

PORT_NUMBER_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 a port number.

/[1-9][0-9]{0,3}|[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5]/
SERVICE_NAME_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 a service name.

/[A-Za-z][A-Za-z0-9]*(?:[\/_-][A-Za-z0-9]+)*\*?/
PORT_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 either a port number or service name.

/(?:#{PORT_NUMBER_REGEXP}|#{SERVICE_NAME_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 either a port number or service name.

/\A#{PORT_REGEXP}\z/

Instance Method Summary collapse

Constructor Details

#initializePort

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



212
213
214
# File 'lib/nmap/command.rb', line 212

def initialize
  super(range: 1..65535)
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 the given value.

Parameters:

  • value (Integer, String)

    The port number value to format.

Returns:

  • (String)

    The formatted port number.



248
249
250
251
252
253
254
255
# File 'lib/nmap/command.rb', line 248

def format(value)
  case value
  when String
    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 the given port number value.

Parameters:

  • value (Object)

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



226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/nmap/command.rb', line 226

def validate(value)
  case value
  when String
    if value =~ REGEXP
      return true
    else
      return [false, "must be a valid port number or service name (#{value.inspect})"]
    end
  else
    super(value)
  end
end