Skip to content

Instantly share code, notes, and snippets.

@hogelog
Created July 15, 2022 07:21
Show Gist options
  • Save hogelog/d7ed9317649c4adcee3b097a7852ac06 to your computer and use it in GitHub Desktop.
Save hogelog/d7ed9317649c4adcee3b097a7852ac06 to your computer and use it in GitHub Desktop.
require "ipaddr"
text = ARGF.read
cidrs = []
while (match = text.match(%r[(\d+\.\d+\.\d+\.\d+/\d+)]))
cur = IPAddr.new(match[1])
cur_addrs = cur.to_range.to_a
cidrs.each do |cidr|
puts "overlap: #{cur} x #{cidr}" if cur_addrs.any?{|cur_addr| cidr.to_range.cover?(cur_addr) }
end
cidrs << cur
cidrs.uniq!
text = match.post_match
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment