Class: Masscan::Command::Target 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 --range option and ips argument(s).

Since:

  • 0.3.0

Constant Summary collapse

DECIMAL_OCTET_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 for validating decimal octets (0-255).

Since:

  • 0.3.0

/(?<=[^\d]|^)(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])(?=[^\d]|$)/
IPV4_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 for validating IPv4 addresses or CIDR ranges.

Since:

  • 0.3.0

%r{#{DECIMAL_OCTET_REGEXP}(?:\.#{DECIMAL_OCTET_REGEXP}){3}(?:/\d{1,2})?}
IPV6_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 for validating IPv6 addresses or CIDR ranges.

Since:

  • 0.3.0

%r{
 (?:[0-9a-f]{1,4}:){6}#{IPV4_REGEXP}|
 (?:[0-9a-f]{1,4}:){5}[0-9a-f]{1,4}:#{IPV4_REGEXP}|
 (?:[0-9a-f]{1,4}:){5}:[0-9a-f]{1,4}:#{IPV4_REGEXP}|
 (?:[0-9a-f]{1,4}:){1,1}(?::[0-9a-f]{1,4}){1,4}:#{IPV4_REGEXP}|
 (?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,3}:#{IPV4_REGEXP}|
 (?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,2}:#{IPV4_REGEXP}|
 (?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,1}:#{IPV4_REGEXP}|
 :(?::[0-9a-f]{1,4}){1,5}:#{IPV4_REGEXP}|
 (?:(?:[0-9a-f]{1,4}:){1,5}|:):#{IPV4_REGEXP}|
 (?:[0-9a-f]{1,4}:){1,1}(?::[0-9a-f]{1,4}){1,6}(?:/\d{1,3})?|
 (?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,5}(?:/\d{1,3})?|
 (?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,4}(?:/\d{1,3})?|
 (?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,3}(?:/\d{1,3})?|
 (?:[0-9a-f]{1,4}:){1,5}(?::[0-9a-f]{1,4}){1,2}(?:/\d{1,3})?|
 (?:[0-9a-f]{1,4}:){1,6}(?::[0-9a-f]{1,4}){1,1}(?:/\d{1,3})?|
 [0-9a-f]{1,4}(?::[0-9a-f]{1,4}){7}(?:/\d{1,3})?|
 :(?::[0-9a-f]{1,4}){1,7}(?:/\d{1,3})?|
 (?:(?:[0-9a-f]{1,4}:){1,7}|:):(?:/\d{1,3})?
}x
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 for validating masscan target IPs or IP ranges.

Since:

  • 0.3.0

/\A(?:#{IPV4_REGEXP}|#{IPV6_REGEXP})\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 IP or IP range target value.

Parameters:

  • value (IPAddr, String, #to_s)

    The IP or IP range 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



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/masscan/command.rb', line 505

def validate(value)
  case value
  when IPAddr
    return true
  else
    valid, message = super(value)

    unless valid
      return [valid, message]
    end

    string = value.to_s

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

    return true
  end
end