Class: Nmap::Command::PortRange Private

Inherits:
Port
  • Object
show all
Defined in:
lib/nmap/command.rb

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.

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.

/(?:#{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.

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

Parameters:

  • value (Range, Integer, String)

Returns:

  • (String)


299
300
301
302
303
304
305
306
# File 'lib/nmap/command.rb', line 299

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

Parameters:

  • value (Object)

Returns:

  • (true, (false, String))


265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/nmap/command.rb', line 265

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, "not a valid port range (#{value.inspect})"]
    end

    return true
  else
    super(value)
  end
end