From: Chuck Remes on 7 Jun 2010 17:49 On Jun 7, 2010, at 4:26 PM, Aaron D. Gifford wrote: > Without having looked at your library, does it support IP ranges (i.e. > blocks of IP addresses that are contiguous but do not necessarily > exactly match a subnet boundary)? Perhaps as a separate class? > > Can one do this? > > ip = IPAddress.new("10.0.0.1") ## No prefix specified... will it > assume /32 IPv4 host prefix? > > Also, are there methods to determine if a network (or range, if > supported) contains another IP, network, or range? Something like: > > ip = IPAddress.new("10.0.0.1/32") > net = IPAddress.new("10.0.0.0/24") > puts "IP is contained by network" if net.contains?(ip) || ip.is_in?(net) Taking two seconds to peruse the (very simple) source would have given you your answer. http://github.com/bluemonk/ipaddress/blob/master/lib/ipaddress/ipv4.rb#L499 cr
From: Brian Candler on 7 Jun 2010 18:17 Aaron D. Gifford wrote: > Without having looked at your library, does it support IP ranges (i.e. > blocks of IP addresses that are contiguous but do not necessarily > exactly match a subnet boundary)? Perhaps as a separate class? ...or it could be just a regular Ruby range, like this: >> require 'ip' => true >> r = IP.new("10.0.0.6")..IP.new("10.0.0.10") => #<IP::V4 10.0.0.6>..#<IP::V4 10.0.0.10> >> r.each { |x| p x } #<IP::V4 10.0.0.6> #<IP::V4 10.0.0.7> #<IP::V4 10.0.0.8> #<IP::V4 10.0.0.9> #<IP::V4 10.0.0.10> => #<IP::V4 10.0.0.6>..#<IP::V4 10.0.0.10> (It's an interesting idea that perhaps an IP object should be a start+end range, but then you need a way to show an IP as a string when it's not suitable for addr/len form) -- Posted via http://www.ruby-forum.com/.
From: bluemonk on 8 Jun 2010 03:40 On Jun 6, 9:51 pm, Brian Candler <b.cand...(a)pobox.com> wrote: > BTW, a little while ago I released a small library,http://github.com/deploy2/ruby-ip > and it seems we've had some similar ideas (such as separate subclasses > for v4 and v6). I meant to add things like IP#each but never got around > to it :-) Hi Brian I wasn't aware of your library when I started writing mine. I'm not a fan of duplicating efforts, pity we didn't see each other :) Very nice job BTW Regards, Marco
From: bluemonk on 8 Jun 2010 03:53
On Jun 7, 11:26 pm, "Aaron D. Gifford" <astound...(a)gmail.com> wrote: > Without having looked at your library, does it support IP ranges (i.e. > blocks of IP addresses that are contiguous but do not necessarily > exactly match a subnet boundary)? Perhaps as a separate class? Not yet, I plan to introduce ranges in 0.7.0, I'm still working on a meaningful notation. > Can one do this? > > ip = IPAddress.new("10.0.0.1") ## No prefix specified... will it > assume /32 IPv4 host prefix? No, it will assume the classful subnet mask (/8 in this case) http://marcoceresa.com/ipaddress/classes/IPAddress/IPv4.html#M000008 However this behaviour is currently under discussion, as it is one major break in respect to IPAddr (the other being #to_s). It may change in the future. > Also, are there methods to determine if a network (or range, if > supported) contains another IP, network, or range? Something like: > > ip = IPAddress.new("10.0.0.1/32") > net = IPAddress.new("10.0.0.0/24") > puts "IP is contained by network" if net.contains?(ip) || ip.is_in?(net) Yes: http://marcoceresa.com/ipaddress/classes/IPAddress/IPv4.html#M000034 Regards, Marco |