From: Paul Battley Date: 2006-04-21T01:52:27+09:00 Subject: Re: Converting IP range to array of IP's On 20/04/06, Kris wrote:> I'm looking to convert an IP string (ranges, subnet masks or wild-carded> IP's) in to an array of IP strings: The dotted notation is just a human-readable version of a 32-bitvalue, so you can do this: def dq_to_int(dq) parts = dq.split('.').map{ |s| s.to_i }.reverse (0..3).inject(0){ |r,i| r + parts[i] * (0x100**i) }end def int_to_dq(int) (0..3).map{ |i| ((int / (0x100**(3-i))) & 0xFF).to_s }.join('.')end (dq_to_int('192.168.1.1')..dq_to_int('192.168.1.5')).map{ |i| int_to_dq(i) }# => ["192.168.1.1", "192.168.1.2", "192.168.1.3", "192.168.1.4", "192.168.1.5"] Paul.