Created
April 16, 2016 05:55
-
-
Save bdashrad/0c9234f48b8f4eaf0f05b8a5e9466f9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'netaddr' | |
regexfile = ARGV[0] | |
testfile = ARGV[1] | |
regex = Regexp.new(File.read(regexfile)).freeze | |
File.foreach(testfile) do |test| | |
if /-/ =~ test | |
lower = NetAddr::CIDR.create(test.split('-').first.strip) | |
upper = NetAddr::CIDR.create(test.split('-').last.strip) | |
NetAddr.range(lower, upper).each do |ip| | |
puts ip unless regex =~ ip | |
end | |
else | |
NetAddr::CIDR.create(test.strip).enumerate.each do |ip| | |
puts ip unless regex =~ ip | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment