From: Peter Ertl Date: 2006-04-21T01:28:41+09:00 Subject: Re: Converting IP range to array of IP's had some fun with that :-) require 'pp' def ip_range(range, &block) start, delta = range.split("-").map do |ipstr| ipstr.split(".").map do |number| number.to_i end end (0..3).each do |pos| delta[pos] -= start[pos] end (0..delta[0]).each do |d0| (0..delta[1]).each do |d1| (0..delta[2]).each do |d2| (0..delta[3]).each do |d3| yield [start[0] + d0, start[1] + d1, start[2] + d2, start[3] + d3] end end end end end ip_range("192.168.1.1 - 192.169.2.5") do |ip| pp ip end > --- Urspr�ngliche Nachricht --- > Von: Kris > An: ruby-talk@ruby-lang.org (ruby-talk ML) > Betreff: Converting IP range to array of IP's > Datum: Fri, 21 Apr 2006 01:05:59 +0900 > > I'm looking to convert an IP string (ranges, subnet masks or wild-carded > IP's) in to an array of IP strings: > > eg. "192.168.1.1 - 192.168.1.5" => ["192.168.1.1", "192.168.1.2", > "192.168.1.3", "192.168.1.4", "192.168.1.5"] > > Before I embark on this, is there already a ruby class that does it or > some of this? > > I've checked out the NET classes already. > > Many thanks, K. > > -- > Posted via http://www.ruby-forum.com/. >