Class: IPRange

Inherits:
Object
  • Object
show all
Extended by:
Logging
Defined in:
lib/ip_range.rb

Constant Summary collapse

@@log =
init_logger(STDOUT)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

init_logger, log_level=, log_target=

Constructor Details

#initialize(args) ⇒ IPRange

create an IP-range



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ip_range.rb', line 55

def initialize(args) 
  @log = @@log
  if args && args.length >= 2

    #first IP
    @first = ip_to_number args[0]
    #last IP
    @last = ip_to_number args[1]
    if @last && @first && ( @last < @first )
      @log.error('ERROR! Last IP is smaller than first. Aborting!') 
      exit false
    end
    @vrange = args[0,2] 
  end
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



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

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



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

def last
  @last
end

#vrangeObject (readonly)

Returns the value of attribute vrange.



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

def vrange
  @vrange
end

Instance Method Details

#in_range?(cip) ⇒ Boolean

check IP in range ?

Returns:

  • (Boolean)


46
47
48
# File 'lib/ip_range.rb', line 46

def in_range?(cip)
  (@first..@last) === ip_to_number(cip)
end

#irangeObject



50
51
52
# File 'lib/ip_range.rb', line 50

def irange()
  [@first, @last]
end