Class: IPRange

Inherits:
Object
  • Object
show all
Includes:
BasicLogging
Defined in:
lib/ip_range.rb

Constant Summary

Constants included from BasicLogging

BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN

Instance Attribute Summary collapse

Attributes included from BasicLogging

#log_level, #target

Instance Method Summary collapse

Methods included from BasicLogging

is_muted?, #log, mute, #set_level, #set_target

Constructor Details

#initialize(args) ⇒ IPRange

create an IP-range



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ip_range.rb', line 49

def initialize(args) 
  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 )
      error('ERROR! Last IP is smaller than the first (' << @first.to_s << ' - ' << @last.to_s << ')')
      error('Aborting!') 
      exit false
    end
    @vrange = args[0,2] 
  end
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



65
66
67
# File 'lib/ip_range.rb', line 65

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



65
66
67
# File 'lib/ip_range.rb', line 65

def last
  @last
end

#vrangeObject (readonly)

Returns the value of attribute vrange.



65
66
67
# File 'lib/ip_range.rb', line 65

def vrange
  @vrange
end

Instance Method Details

#in_range?(cip) ⇒ Boolean

check IP in range ?

Returns:

  • (Boolean)


40
41
42
# File 'lib/ip_range.rb', line 40

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

#irangeObject



44
45
46
# File 'lib/ip_range.rb', line 44

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