Hi All,
I made this little perl script below to examine two files, both being log files created by a packet sniffer. Mainly what I'm doing is seaching each file for the same packet ID number (src and dst addys and ports are already known to match) and taking the differences between the timestamps recorded by the sniffer at each endpoint. The problem that I'm having is that the way it is set up now is VERY SLOW as it loops through a file each time looking for a match. Does anyone know how I can improve on this? Thank you for your help!
#####################################################
$local_log = @ARGV[0];
$remote_log = @ARGV[1];
open( rl_txt, ">remote_minus_local.txt" ) or die "Cannot access remote_minus_local.txt";
open( lm_txt, ">local_minus_remote.txt" ) or die "Cannot access local_minus_remote.txt";
open( file1, $local_log );
while(<file1>)
{
@l_in = split(' ', $_);
open( file2, $remote_log );
while(<file2>)
{
@r_in = split(' ', $_);
if( ($l_in[7] == $r_in[7]) )
{
$temp = $r_in[1] - $l_in[1];
print rm_txt "$l_in[1] $l_in[2] $l_in[3] $l_in[5] $l_in[6] $l_in[7] $l_in[10] $temp\n";
$temp2 = $l_in[1] - $r_in[1];
print lm_txt "$l_in[1] $l_in[2] $l_in[3] $l_in[5] $l_in[6] $l_in[7] $l_in[10] $temp2\n";
last;
}
}
}
close (file1);
close (file2);
close (rm_txt);
close (lm_txt);
##########################################################
I made this little perl script below to examine two files, both being log files created by a packet sniffer. Mainly what I'm doing is seaching each file for the same packet ID number (src and dst addys and ports are already known to match) and taking the differences between the timestamps recorded by the sniffer at each endpoint. The problem that I'm having is that the way it is set up now is VERY SLOW as it loops through a file each time looking for a match. Does anyone know how I can improve on this? Thank you for your help!
#####################################################
$local_log = @ARGV[0];
$remote_log = @ARGV[1];
open( rl_txt, ">remote_minus_local.txt" ) or die "Cannot access remote_minus_local.txt";
open( lm_txt, ">local_minus_remote.txt" ) or die "Cannot access local_minus_remote.txt";
open( file1, $local_log );
while(<file1>)
{
@l_in = split(' ', $_);
open( file2, $remote_log );
while(<file2>)
{
@r_in = split(' ', $_);
if( ($l_in[7] == $r_in[7]) )
{
$temp = $r_in[1] - $l_in[1];
print rm_txt "$l_in[1] $l_in[2] $l_in[3] $l_in[5] $l_in[6] $l_in[7] $l_in[10] $temp\n";
$temp2 = $l_in[1] - $r_in[1];
print lm_txt "$l_in[1] $l_in[2] $l_in[3] $l_in[5] $l_in[6] $l_in[7] $l_in[10] $temp2\n";
last;
}
}
}
close (file1);
close (file2);
close (rm_txt);
close (lm_txt);
##########################################################