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

Instance Method Summary collapse

Methods included from BasicLogging

#clear_log, is_muted?, #level, #log, #log_name, mute, #set_level, #set_target, #target

Constructor Details

#initialize(args) ⇒ IPRange

create an IP-range



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

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

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



67
68
69
# File 'lib/ip_range.rb', line 67

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



67
68
69
# File 'lib/ip_range.rb', line 67

def last
  @last
end

#vrangeObject (readonly)

Returns the value of attribute vrange.



67
68
69
# File 'lib/ip_range.rb', line 67

def vrange
  @vrange
end

Instance Method Details

#in_range?(cip) ⇒ Boolean

check IP in range ?

Returns:

  • (Boolean)


42
43
44
# File 'lib/ip_range.rb', line 42

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

#irangeObject



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

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