Class: Masscan::Command::MACAddress Private

Inherits:
CommandMapper::Types::Str
  • 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 the type for the --adapter-mac and --router-mac options.

Since:

  • 0.3.0

Constant Summary collapse

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 a MAC address.

Since:

  • 0.3.0

/\A[A-Fa-f0-9]{2}(?::[A-Fa-f0-9]{2}){5}\z/

Instance Method Summary collapse

Instance Method Details

#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 a MAC address value.

Parameters:

  • value (String, #to_s)

    The MAC address 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



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/masscan/command.rb', line 437

def validate(value)
  valid, message = super(value)

  unless valid
    return [valid, message]
  end

  string = value.to_s

  unless string =~ REGEXP
    return [false, "invalid MAC address (#{value.inspect})"]
  end

  return true
end