-
-
Save IceDragon200/d2567f01e5d3d3530999 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def parse_ip_string(line) | |
line.scan(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/).each do |addr| | |
split_array = addr.split(".") | |
return split_array.map{ |str| str.rjust(3, '0') }.join '.' | |
end | |
nil | |
end | |
unless ARGV.size == 1 | |
puts "Invalid number of arguments?" | |
else | |
filename = ARGV[0] | |
ip_hash = Hash.new(0) | |
File.open(filename, 'r') do |in_file| | |
in_file.each_line do |line| | |
ip_string = parse_ip_string(line) | |
if ip_hash.key?(ip_string) # the ip_string was found | |
ip_hash[ip_string] += 1 | |
else | |
ip_hash[ip_string] = ip_hash.default | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment