I have this assignment which requires me to take the source ip and destination port from this log file and add them to a database table i created using Perl dbi sqlite. i have tried to write a script that does that but it does not seem to work. i would appreciate any help. The log file is available at http://fleming0.flemingc.on.ca/~chbaker/COMP234-Perl/sample.log
here is the code i have so far.
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my %ip2port;
my $IPCount = keys %ip2port;
my $portCount = 0;
my $filename = "./sample.log";
open my $LOG, "<", $filename or die "Can't open $filename: $!";
LINE: while (my $line = <$LOG>) {
my ($src_id) = $line =~ m!SRC=([.\d]+)!gis; my ($dst_port) = $line =~ m!DPT=([.\d]+)!gis;
my $dbh = DBI->connect(
"dbi:SQLite:dbname=test.db",
"",
"",
{ RaiseError => 1 },
) or die $DBI::errstr;
$dbh->do("INSERT INTO probes VALUES($src_id, $dst_port )");
$dbh->do("INSERT INTO probes VALUES(2,'$dst_port',57127)");
my $sth = $dbh->prepare("SELECT SQLITE_VERSION()");
$sth->execute();
my $ver = $sth->fetch();
print @$ver;
print "\n";
$sth->finish();
$dbh->disconnect();
}