Class: Rex::Socket::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/socket/range_walker.rb

Overview

A range of IP addresses

Direct Known Subclasses

Host

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start = nil, stop = nil, options = nil) ⇒ Range

Returns a new instance of Range.

Parameters:

  • start (Fixnum) (defaults to: nil)
  • stop (Fixnum) (defaults to: nil)
  • options (Hash) (defaults to: nil)

    Recognized keys are:

    • :ipv6

    • :scope_id



510
511
512
513
514
# File 'lib/rex/socket/range_walker.rb', line 510

def initialize(start=nil, stop=nil, options=nil)
  @start = start
  @stop = stop
  @options = options || {}
end

Instance Attribute Details

#optionsHash

Returns:

  • (Hash)


503
504
505
# File 'lib/rex/socket/range_walker.rb', line 503

def options
  @options
end

#startFixnum

The first address in this range, as a number

Returns:

  • (Fixnum)


496
497
498
# File 'lib/rex/socket/range_walker.rb', line 496

def start
  @start
end

#stopFixnum

The last address in this range, as a number

Returns:

  • (Fixnum)


500
501
502
# File 'lib/rex/socket/range_walker.rb', line 500

def stop
  @stop
end

Instance Method Details

#==(other) ⇒ Boolean

Compare attributes with other

Parameters:

Returns:

  • (Boolean)


519
520
521
# File 'lib/rex/socket/range_walker.rb', line 519

def ==(other)
  (other.start == start && other.stop == stop && other.ipv6? == ipv6? && other.options == options)
end

#ipv6?Boolean

Whether this Range contains IPv6 or IPv4 addresses

Returns:

  • (Boolean)


532
533
534
# File 'lib/rex/socket/range_walker.rb', line 532

def ipv6?
  options[:ipv6]
end

#lengthFixnum Also known as: count

The number of addresses in this Range

Returns:

  • (Fixnum)


525
526
527
# File 'lib/rex/socket/range_walker.rb', line 525

def length
  stop - start + 1
end