summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Mackintosh <m@zyp.io>2015-03-22 23:53:32 -0400
committerMike Mackintosh <m@zyp.io>2015-03-22 23:53:32 -0400
commit6bf73cfccf4f3b0b17fa8926b47ee26710527ea0 (patch)
tree0fb6a460dfeb6812c09f8a8ed25869d785e0c695 /lib
parent09bde2a5ef66884ab63f8649a15514840c03dd83 (diff)
downloadipaddress-6bf73cfccf4f3b0b17fa8926b47ee26710527ea0.tar.gz
added #to range and fixed #40
Diffstat (limited to 'lib')
-rw-r--r--lib/ipaddress/ipv4.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb
index fc2976a..eea73ac 100644
--- a/lib/ipaddress/ipv4.rb
+++ b/lib/ipaddress/ipv4.rb
@@ -641,6 +641,26 @@ module IPAddress;
alias_method :arpa, :reverse
#
+ # Return a list of IP's between @address
+ # and the supplied IP
+ #
+ # ip = IPAddress("172.16.100.51/32")
+ #
+ # ip.to("172.16.100.100")
+ # #=> ["172.16.100.51",
+ # "172.16.100.52",
+ # ...
+ # "172.16.100.99",
+ # "172.16.100.100"]
+ #
+ def to(e)
+ unless e.is_a? IPAddress::IPv4
+ e = IPv4.new(e)
+ end
+
+ Range.new(@u32, e.to_u32).map{|i| IPAddress.ntoa(i) }
+ end
+ #
# Splits a network into different subnets
#
# If the IP Address is a network, it can be divided into
@@ -1028,7 +1048,7 @@ module IPAddress;
# Tweaked to remove the #upto(32)
def newprefix(num)
- return @prefix + (Math::log2(num).to_i)
+ return @prefix + (Math::log2(num).ceil )
end
def sum_first_found(arr)