Class: Masscan::Command::Port Private

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

Since:

  • 0.3.0

Direct Known Subclasses

PortRange

Constant Summary collapse

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

Since:

  • 0.3.0

/[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]/
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.

Since:

  • 0.3.0

/\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.

Since:

  • 0.3.0



111
112
113
# File 'lib/masscan/command.rb', line 111

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

Parameters:

  • value (Integer, String)

    The given port number.

Returns:

  • (String)

    The formatted port number.

Since:

  • 0.3.0



147
148
149
150
151
152
153
154
# File 'lib/masscan/command.rb', line 147

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

Since:

  • 0.3.0



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/masscan/command.rb', line 125

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

    return true
  else
    super(value)
  end
end