M
mhoer
Im fairly new to perl and i have a problem. I am sorting a firewall log
into a plain text file. I have it doing everything except for 1 thing
and that is to see a list source and destination IP addresses. I got it
to print out the data in neat columns.
The only thing i need is to see if multiple attempts come from or
are directed to the same ip address. Then the count how many times for
each mutiple address. If someone could point me in the right direction
or give me an idea would be great.
Example of firewall log:
"Number" "Date" "Time" "Product" "Interface" "Origin" "Type" "Action"
"Service" "Source" "Destination" "Protocol" "Rule" "Source Port" "User"
"Information"
"1" "19Sep2003" "17:00:01" "VPN-1 & FireWall-1" "N100016" "OTC-FW"
"Log" "Drop" "smtp" "192.168.3.98" "64.12.137.152" "tcp" "92" "35719"
"" ""
"2" "19Sep2003" "17:00:01" "VPN-1 & FireWall-1" "N100016" "OTC-FW"
"Log" "Accept" "imap" "DT017484" "emh1.otc.edu" "tcp" "30" "4036" "" ""
"3" "19Sep2003" "17:00:05" "VPN-1 & FireWall-1" "N100016" "OTC-FW"
"Log" "Drop" "389" "172.16.16.179" "192.0.0.8" "udp" "92" "1068" "" ""
######### Here is what i have so far...
#!/usr/bin/perl
# fwlog.plx
use warnings;
use strict;
my $counter = -1;#this is -1 because the first line is not a actual
line that is needed
my $numDrops = 0;
my $numAccepts = 0;
my $numRejects = 0;
my @field; #this is for separating the different fields.
#these are for input and output.
open INPUT, "firewalllog2.txt" or die "Couldn't open file: $!\n";
open OUTPUT, ">fireout.txt" or die "Couldn't open file: $!\n";
while(<INPUT>){
$counter++;#used to find the total
@field = split /" "/, $_;#this breaks up the file into fields from the
spaces
print OUTPUT $field[5],"\t\t";#outputs the origin or name
print OUTPUT $field[9]," " x (40-length($field[9]));#outputs the
source
print OUTPUT $field[10],"\n";#outputs the destination
if ($field[7] =~ /Drop/) {
$numDrops++;#finds how many drops there are.
}
if ($field[7] =~ /Accept/) {
$numAccepts++;#finds how many accepts there are.
}
if ($field[7] =~ /Reject/){
$numRejects++;#finds how many rejects there are
}
}
# The total of logs, drops, acceps,and rejects
print OUTPUT "\n\nTotal: ",$counter,"\n\n";
print OUTPUT "Action:\n";
print OUTPUT "\tDrops (",$numDrops,")\n";
print OUTPUT "\tAccepts (",$numAccepts,")\n";
print OUTPUT "\tRejects (",$numRejects,")\n";
#still needs to find same sources and destinations and tell how many
there are.
into a plain text file. I have it doing everything except for 1 thing
and that is to see a list source and destination IP addresses. I got it
to print out the data in neat columns.
The only thing i need is to see if multiple attempts come from or
are directed to the same ip address. Then the count how many times for
each mutiple address. If someone could point me in the right direction
or give me an idea would be great.
Example of firewall log:
"Number" "Date" "Time" "Product" "Interface" "Origin" "Type" "Action"
"Service" "Source" "Destination" "Protocol" "Rule" "Source Port" "User"
"Information"
"1" "19Sep2003" "17:00:01" "VPN-1 & FireWall-1" "N100016" "OTC-FW"
"Log" "Drop" "smtp" "192.168.3.98" "64.12.137.152" "tcp" "92" "35719"
"" ""
"2" "19Sep2003" "17:00:01" "VPN-1 & FireWall-1" "N100016" "OTC-FW"
"Log" "Accept" "imap" "DT017484" "emh1.otc.edu" "tcp" "30" "4036" "" ""
"3" "19Sep2003" "17:00:05" "VPN-1 & FireWall-1" "N100016" "OTC-FW"
"Log" "Drop" "389" "172.16.16.179" "192.0.0.8" "udp" "92" "1068" "" ""
######### Here is what i have so far...
#!/usr/bin/perl
# fwlog.plx
use warnings;
use strict;
my $counter = -1;#this is -1 because the first line is not a actual
line that is needed
my $numDrops = 0;
my $numAccepts = 0;
my $numRejects = 0;
my @field; #this is for separating the different fields.
#these are for input and output.
open INPUT, "firewalllog2.txt" or die "Couldn't open file: $!\n";
open OUTPUT, ">fireout.txt" or die "Couldn't open file: $!\n";
while(<INPUT>){
$counter++;#used to find the total
@field = split /" "/, $_;#this breaks up the file into fields from the
spaces
print OUTPUT $field[5],"\t\t";#outputs the origin or name
print OUTPUT $field[9]," " x (40-length($field[9]));#outputs the
source
print OUTPUT $field[10],"\n";#outputs the destination
if ($field[7] =~ /Drop/) {
$numDrops++;#finds how many drops there are.
}
if ($field[7] =~ /Accept/) {
$numAccepts++;#finds how many accepts there are.
}
if ($field[7] =~ /Reject/){
$numRejects++;#finds how many rejects there are
}
}
# The total of logs, drops, acceps,and rejects
print OUTPUT "\n\nTotal: ",$counter,"\n\n";
print OUTPUT "Action:\n";
print OUTPUT "\tDrops (",$numDrops,")\n";
print OUTPUT "\tAccepts (",$numAccepts,")\n";
print OUTPUT "\tRejects (",$numRejects,")\n";
#still needs to find same sources and destinations and tell how many
there are.