Extracting individual IP addresses

142 views Asked by At

How can I extract each individual IP address from the array below?

strList = ["10.5.5.5 - 10.5.5.8"]

The end result should look like this:

newList = ["10.5.5.5","10.5.5.6","10.5.5.7","10.5.5.8"]

Do you guys have any ideas?

1

There are 1 answers

0
Cary Swoveland On BEST ANSWER

You can do that as follows:

require 'ipaddr'

(IPAddr.new("10.5.5.5")..IPAddr.new("10.5.5.8")).map(&:to_s)
  #=> ["10.5.5.5", "10.5.5.6", "10.5.5.7", "10.5.5.8]