def range(lower, upper, options=nil)
known_args = [:Bitstep, :Inclusive, :Limit, :Objectify, :Short, :Size]
list = []
bitstep = 1
objectify = false
short = false
size_only = false
inclusive = false
limit = nil
if ( !lower.kind_of?(NetAddr::CIDR) )
begin
lower = NetAddr::CIDR.create(lower)
rescue Exception => error
raise ArgumentError, "Argument 'lower' raised the following " +
"errors: #{error}"
end
end
if ( !upper.kind_of?(NetAddr::CIDR))
begin
upper = NetAddr::CIDR.create(upper)
rescue Exception => error
raise ArgumentError, "Argument 'upper' raised the following " +
"errors: #{error}"
end
end
if (options)
raise ArgumentError, "Hash expected for argument 'options' but #{options.class} provided." if (!options.kind_of?(Hash))
NetAddr.validate_args(options.keys,known_args)
if( options.has_key?(:Bitstep) )
bitstep = options[:Bitstep]
end
if( options.has_key?(:Objectify) && options[:Objectify] == true )
objectify = true
end
if( options.has_key?(:Short) && options[:Short] == true )
short = true
end
if( options.has_key?(:Size) && options[:Size] == true )
size_only = true
end
if( options.has_key?(:Inclusive) && options[:Inclusive] == true )
inclusive = true
end
if( options.has_key?(:Limit) )
limit = options[:Limit]
end
end
if (lower.version == upper.version)
version = lower.version
boundaries = [lower.to_i(:ip), upper.to_i(:ip)]
boundaries.sort
else
raise VersionError, "Provided NetAddr::CIDR objects are of different IP versions."
end
if (!inclusive)
my_ip = boundaries[0] + 1
end_ip = boundaries[1]
else
my_ip = boundaries[0]
end_ip = boundaries[1] + 1
end
if (!size_only)
until (my_ip >= end_ip)
if (!objectify)
my_ip_s = ip_int_to_str(my_ip, version)
my_ips = shorten(my_ips) if (short && version == 6)
list.push(my_ip_s)
else
list.push( cidr_build(version,my_ip) )
end
my_ip = my_ip + bitstep
if (limit)
limit = limit -1
break if (limit == 0)
end
end
else
list = end_ip - my_ip
end
return(list)
end