Class: Ronin::Recon::Values::IPRange

Inherits:
Ronin::Recon::Value show all
Defined in:
lib/ronin/recon/values/ip_range.rb

Overview

Represents a IP CIDR or glob range.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ronin::Recon::Value

#==, parse, #to_csv, #to_json

Constructor Details

#initialize(range) ⇒ IPRange

Initializes the IP range object.

Parameters:

  • range (Ronin::Support::Network::IPRange, String)

    The IP range string.

Raises:

  • (ArgumentError)

    The given range was not an Ronin::Support::Network::IPRange or String object.



51
52
53
54
55
56
57
58
59
60
# File 'lib/ronin/recon/values/ip_range.rb', line 51

def initialize(range)
  @range = case range
           when Support::Network::IPRange
             range
           when String
             Support::Network::IPRange.new(range)
           else
             raise(ArgumentError,"IP range must be either an IPAddr or String: #{range.inspect}")
           end
end

Instance Attribute Details

#rangeRonin::Support::Network::IPRange (readonly)

The IP range.

Returns:

  • (Ronin::Support::Network::IPRange)


39
40
41
# File 'lib/ronin/recon/values/ip_range.rb', line 39

def range
  @range
end

Class Method Details

.value_type:ip_range

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.

Note:

This is used internally to map a recon value class to a printable type.

Returns the type or kind of recon value.

Returns:

  • (:ip_range)


148
149
150
# File 'lib/ronin/recon/values/ip_range.rb', line 148

def self.value_type
  :ip_range
end

Instance Method Details

#===(other) ⇒ Boolean

Case equality method used for fuzzy matching.

Parameters:

  • other (Value)

    The other value to compare.

Returns:



86
87
88
89
90
91
92
# File 'lib/ronin/recon/values/ip_range.rb', line 86

def ===(other)
  case other
  when IPRange then @range === other.range
  when IP      then include?(other.address)
  else              false
  end
end

#as_jsonHash{Symbol => Object}

Coerces the IP range value into JSON.

Returns:

  • (Hash{Symbol => Object})

    The Ruby Hash that will be converted into JSON.



133
134
135
# File 'lib/ronin/recon/values/ip_range.rb', line 133

def as_json
  {type: :ip_range, range: @range.to_s}
end

#eql?(other) ⇒ Boolean

Compares the value to another value.

Parameters:

Returns:

  • (Boolean)


101
102
103
# File 'lib/ronin/recon/values/ip_range.rb', line 101

def eql?(other)
  other.kind_of?(self.class) && @range == other.range
end

#hashInteger

The "hash" value of the IP range.

Returns:

  • (Integer)

    The hash value of #range.



111
112
113
# File 'lib/ronin/recon/values/ip_range.rb', line 111

def hash
  [self.class, @range].hash
end

#include?(ip) ⇒ Boolean

Determines if an IP address exists within the IP range.

Parameters:

  • ip (Ronin::Support::Network::IPRange, IPAddr, String)

    The IP address to test.

Returns:

  • (Boolean)

    Indicates whether the IP address exists within the IP range.



71
72
73
# File 'lib/ronin/recon/values/ip_range.rb', line 71

def include?(ip)
  @range.include?(ip)
end

#to_sString Also known as: to_str

Converts the IP range object to a String.

Returns:

  • (String)

    The IP range.



121
122
123
# File 'lib/ronin/recon/values/ip_range.rb', line 121

def to_s
  @range.to_s
end