Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2014 00:34
Show Gist options
  • Save anonymous/52c7066a84fd88d85d3f to your computer and use it in GitHub Desktop.
Save anonymous/52c7066a84fd88d85d3f to your computer and use it in GitHub Desktop.
# Assignment 5
# Justin Beitz
unless ARGV.size == 1
puts "Invalid number of arguments?"
else
in_file = File.new(ARGV[0], 'r')
in_file.each_line do |line|
#Stores every match into an array
match_array = line.scan(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)
#Walk through array
match_array.each do |x|
#Split array by each .
split_array = x.split(".")
#rjust by 3
rjust_split_array = split_array.to_s.rjust(3, '0')
puts rjust_split_array
#combine backtogether
end
#Format IP before storing as key
#Split by . to check each octet - each will be string, need an int
#use to_s.rjust - takes each split, format to leading 0 with max of 3 digits
#combine back together as one
#Store as key
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment