dru145 has asked for the wisdom of the Perl Monks concerning the following question:
What I am trying to do is check and see if an ip address along with a service (http) remains constant for a certain number of entries (we'll say 5 for this example). I need the script to be able to determine if ANY service shows up 5 times with the ip address given. Here is what I've come up with:1;30Nov2001;17:08:25;192.148.14.2;log;accept;;hme0;outbound;udp;192.14 +8.84.4;24.248.34.99;domain-udp;1103;43;85;;;;;;;;;;;;;;; 2;30Nov2001;17:08:25;192.148.14.2;log;drop;;hme0;inbound;tcp;43.228.94 +.254;192.148.11.47;netbios-ssn;18803;48;89;;;;;;;;;;;;;;; 3;30Nov2001;17:08:26;192.148.14.2;log;drop;;hme0;inbound;tcp;45.93.220 +.223;192.148.24.139;auth;1323;40;89;;;;;;;;;;;;;;; 4;30Nov2001;17:08:26;192.148.14.2;log;drop;;hme0;inbound;tcp;45.93.220 +.223;192.148.24.139;auth;1323;40;89;;;;;;;;;;;;;;; 5;30Nov2001;17:08:26;192.148.14.2;log;accept;;qfe2;inbound;tcp;192.148 +.84.144;24.248.34.97;http;4719;44;85;;;;;;;;;;;;;;; 6;30Nov2001;17:08:26;192.148.14.2;log;accept;;hme0;outbound;tcp;192.14 +8.84.144;24.248.34.97;http;4719;44;85;;;;;;;;;;;;;;; 7;30Nov2001;17:08:26;192.148.14.2;log;accept;;qfe2;inbound;tcp;192.148 +.84.144;24.248.34.97;http;4721;44;85;;;;;;;;;;;;;;; 8;30Nov2001;17:08:26;192.148.14.2;log;accept;;hme0;outbound;tcp;192.14 +8.84.144;24.248.34.97;http;4721;44;85;;;;;;;;;;;;;;; 8;30Nov2001;17:08:26;192.148.14.2;log;accept;;hme0;outbound;tcp;192.14 +8.84.144;24.248.34.97;http;4721;44;85;;;;;;;;;;;;;;; 9;30Nov2001;17:08:26;192.148.14.2;log;accept;;qfe2;inbound;tcp;192.148 +.27.154;205.188.145.185;http;4394;44;85;;;;;;;;;;;;;;; 10;30Nov2001;17:08:26;192.148.14.2;log;accept;;hme0;outbound;tcp;192.1 +48.27.154;205.188.145.185;http;4394;44;85;;;;;;;;;;;;;;; 11;30Nov2001;17:08:26;192.148.14.2;log;accept;;qfe2;inbound;tcp;192.14 +8.27.154;205.188.145.185;http;4397;44;85;;;;;;;;;;;;;;; 12;30Nov2001;17:08:26;192.148.14.2;log;accept;;hme0;outbound;tcp;192.1 +48.27.154;205.188.145.185;http;4397;44;85;;;;;;;;;;;;;;;
This works, but when I run it with -w and strict, I get the following output:#!/usr/bin/perl -w use strict; my $log = './log'; + my ($count1, $dst, $service, %count, %hash); my $ip = '24.248.36.97'; open (LOG, $log) or die "Can't open $log: $!"; while (<LOG>){ ($dst, $service) = (split /;/)[11, 12]; $count1++ if ($dst =~ /$ip/); %hash = (service => $service); foreach my $key ($hash{service}){ $count{$key}++; } } foreach my $key1 (keys %count){ print "There are at least 5 occurences of $key1 and $ip.\n" if ($coun +t{$key1} >= 5 && $count1 >= 5); }
Use of uninitialized value in pattern match (m//) at ./misconfig.pl li +ne 13, <LOG> line 36. Use of uninitialized value in hash element at ./misconfig.pl line 17, +<LOG> line 36. There are at least 5 occurences of http and 24.248.36.97.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best way to pick apart log file.
by mkmcconn (Chaplain) on Dec 27, 2001 at 22:45 UTC | |
by Rich36 (Chaplain) on Dec 27, 2001 at 23:00 UTC | |
by dru145 (Friar) on Dec 27, 2001 at 23:21 UTC |