Last active
September 2, 2018 14:45
-
-
Save kthallam/2c06b5aca8191735ad043e736c4972da to your computer and use it in GitHub Desktop.
Ruby script to find out the top 3 ips from which is traffic is coming to your server.
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
# This Script will help you to find the top 3 ips from which is traffic is coming to your servers | |
# Assuming log file is in this format "<IP Address> <Time Stamp> <url requested> <Rest Service Call Method > < Response>" | |
def file_operations(file) | |
str = Array.new | |
temp = Array.new | |
File.open(file).each do |line| | |
str << line.match(" ").pre_match | |
end | |
str.uniq.each do |a| | |
temp << "#{str.count(a.chomp)} #{a}" | |
end | |
temp=temp.sort_by(&:to_i).reverse | |
puts temp[0..2] | |
end | |
file_operations("complete path for the log file)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment