Created
November 6, 2014 02:28
-
-
Save bdashrad/08c37afbf81fede64067 to your computer and use it in GitHub Desktop.
cidr and ip range regex tester
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