Created
July 2, 2018 23:42
-
-
Save rrdein/e680003c7938836fd0e3495ba8ecde45 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
require "rubygems" | |
require "ipaddr" | |
require "nokogiri" | |
sortedNets = [] | |
unSortedNets = [] | |
ARGV[0] = "test.plist" | |
# Open PLIST, get servers as an array cidr_list | |
cidr_list = [] | |
xml_doc = File.open(ARGV[0]) do |f| | |
Nokogiri::XML(f) | |
end | |
server_lines = xml_doc.xpath("//dict//array//string") | |
server_lines.each do |line| | |
data = line.text.split(",") | |
cidr = data[2] | |
cidr_list.push cidr | |
end | |
# cidrs[0] = the index of the original server line | |
# cidrs[1] = number of times the CIDR is contained (by other than itself) | |
# cidrs[2] = number of other CIDRs that contain this one, besides itself | |
# create a function sort_cidrs(cidr_list) that accepts an array of CIDR strings and sorts them | |
cidr_list_length = cidr_list.length | |
cidrs = Array.new(cidr_list_length, [nil, -1, -1]) | |
for i in 0..(cidr_list_length - 1) | |
cidrs[i][0] = i | |
for j in 0..(cidr_list_length - 1) | |
if(IPAddr.new(cidr_list[j]).include? IPAddr.new(cidr_list[i])) | |
cidrs[i][1] += 1 | |
cidrs[j][2] += 1 | |
end | |
puts "#{i} #{j} #{cidrs[0][0]} #{cidrs[0][1]} #{cidrs[0][2]}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment