Guest User

Untitled

a guest
Feb 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. # File: $Id: log_report.pl,v 1.2 2006/11/11 05:07:04 gxr3286 Exp gxr3286 $
  3. # Author: Govind Ramabadran
  4. # Description: This prints out the log report analysis of a log file
  5. # Revisions: $Log: log_report.pl,v $
  6. # Revisions: Revision 1.2 2006/11/11 05:07:04 gxr3286
  7. # Revisions: Fixed it to print as per the sample output
  8. # Revisions:
  9. # Revisions: Revision 1.1 2006/11/11 04:26:04 gxr3286
  10. # Revisions: Initial revision
  11. # Revisions:
  12.  
  13. while (<>)
  14. {
  15. chomp;
  16. $numlines++;
  17. $numchars += length $_;
  18.  
  19. if ($_ =~/^((?:\d{1,3}\.){3}\d{1,3}).*$/)
  20. {
  21. $theIP = $1;
  22. $ip_frequency = {$theIP};
  23. ++$count{$theIP}
  24. }
  25. }
  26.  
  27. #foreach split (' ', lc $_);
  28.  
  29. my @lines = ();
  30. my ($w, $c);
  31. push (@lines, sprintf("%7d\t%s\n", $c, $w)) while (($w, $c) = each (%count));
  32. print "There are $numlines lines and $numchars characters\n";
  33. print " ";
  34. print "IP addresses in order of frequencies of requests:\n";
  35. print sort { $b cmp $a } @lines;
Add Comment
Please, Sign In to add comment