home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / crstats < prev    next >
Text File  |  2020-01-01  |  2KB  |  40 lines

  1. #!/usr/local/bin/wermit +
  2. ;
  3. ; c r s t a t s
  4. ;
  5. ; Reads given codered logfile (see codered script), collects counts by
  6. ; originating host, prints summary to screen.  
  7. ;
  8. ; F. da Cruz, Columbia University, August 2001.
  9. ; Requires C-Kermit 7.0 or later or K95 1.1.20 or later.
  10. ; Illustrates: file i/o, associative arrays, compact substring notation, sort.
  11.  
  12. if not def \%1 exit 1 Usage: \%0 logfilename   ; Check args
  13.  
  14. fopen /read \%c \%1                     ; Open log
  15. if fail exit 1 \f_errmsg()              ; Check that we did
  16. .\%n := 0                               ; Init record counter
  17. while not \f_eof(\%c) {                 ; Loop to read each record
  18.     fread /line \%c line                ; Read one record
  19.     if fail break                       ; Check
  20.     incr \%n                            ; Count
  21.     .a := \s(line[19])                  ; Remove timestamp
  22.     .\%x ::= \findex({"},\m(a)) - 1     ; Remove attack string
  23.     .a := \ftrim(\s(a[1:\%x]))          ; Remove any surrounding whitespace
  24.     .a := \fltrim(\m(a))
  25.     _increment aa<\m(a)>                ; Count a hit from this host
  26. }
  27. fclose \%c                              ; Close log file
  28.  
  29. .\%k := \faaconvert(aa,&a,&b)           ; Convert to pair of regular arrays
  30. .\%u := 0                               ; Local domain counter
  31. array sort /reverse /numeric b a        ; Sort in descending order of hits
  32. for \%i 1 \%k 1 {
  33.     echo \frpad(\&a[\%i],60) \flpad(\&b[\%i],5)  ; Print host and count
  34.     if match \&a[\%i] *128.59* increment \%u     ; Check if local domain
  35. }
  36. echo Hits:               \flpad(\%n,5)  ; Print summary
  37. echo Unique hosts:       \flpad(\%k,5)
  38. echo Unique local hosts: \flpad(\%u,5)
  39. exit 0
  40.