Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perk/tk text area

Status
Not open for further replies.

terranceyaul

Programmer
Apr 3, 2011
1
I have working out two method to get updating log file and print on the textarea, what i done are seem nothing happen so anyone can give me some suggestion?

Code:
#!/usr/local/bin/perl

use Tk;
use File::Tail;

#Main Window
my $mw = new MainWindow;
$mw-> title ("Packet Analyzer Tool");
my $frm_4 = $frm_3 -> Frame(-relief => 'groove', -borderwidth =>2) -> pack(-side => "left");

my $but1 = $frm_1 -> Button(-text => "Start", -command =>\&push_start) -> pack(-side => "left", -anchor => 'nw', -ipadx => 30, -ipady => 35);

my $txt1 = $frm_4 -> Text(-width => 60, -height =>20,-state => "disable") -> pack(-side =>"left",-anchor => 's'); my $srl = $frm_4 -> Scrollbar(-orient=>'v', -command =>yview => $txt);

$txt1 -> configure(-yscrollcommand =>'set',$srl);
$txt1 -> grid(-row=>1, -column=>1);
$srl -> grid(-row=>1, -column=>2,-sticky=>"ns");

MainLoop;

#Executed START BUTTON
sub push_start
{
      chdir( "/var/log/snort");
      foreach my $fol(glob "*.*.*.*")
     {
           print "Opening $fol\n";
           chdir("/var/log/snort/$fol");

                  foreach my $subfile(glob "*:*")
                 {
                          print "opening $subfile\n";
                          push(@files,File::Tail->new(name=>"$subfile",debug=>$debug));
                   }
                   while (1)
                   {
                             ($nfound,$timeleft,@pending)= File::Tail::select(undef,undef,undef,$timeout,@files);

                     unless ($nfound)
                     {
                             print "Nothing to print \n"; 
                      } 
                      else 
                     {
                              foreach(@pending)
                             {
                                    my $line = $_->read;
                                    if ($line =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5} -> (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})/)

                                  $txt1 ->insert('end',  "$_->{"input"}."(".localtime(time).") IP:$1 PORT:$2\n"");
                             }
                   }
             }
}
}

The second way I wrote as below, `tie *STDOUT ref $txt1, $txt1;` i refer to this documentation( But it does not work either.

Code:
#!/usr/local/bin/perl
use Tk;
use File::Tail;

#Main Window
my $mw = new MainWindow;
$mw-> title ("Packet Analyzer Tool");
my $frm_4 = $frm_3 -> Frame(-relief => 'groove', -borderwidth =>2) -> pack(-side => "left");

my $but1 = $frm_1 -> Button(-text => "Start", -command =>\&push_start) -> pack(-side => "left", -anchor => 'nw', -ipadx => 30, -ipady => 35);

my $txt1 = $frm_4 -> Text(-width => 60, -height =>20,-state => "disable") -> pack(-side =>"left",-anchor => 's'); my $srl = $frm_4 -> Scrollbar(-orient=>'v', -command =>yview => $txt);

$txt1 -> configure(-yscrollcommand =>'set',$srl);
$txt1 -> grid(-row=>1, -column=>1);
$srl -> grid(-row=>1, -column=>2,-sticky=>"ns");

MainLoop;

#Executed START BUTTON
sub push_start
{
          chdir( "/var/log/snort");
          foreach my $fol(glob "*.*.*.*")
          {
                    print "Opening $fol\n";
                    chdir("/var/log/snort/$fol");

                    foreach my $subfile(glob "*:*")
                   {
                               print "opening $subfile\n";
                               push(@files,File::Tail->new(name=>"$subfile",debug=>$debug));
                   }
                   while (1)
                   {
                               ($nfound,$timeleft,@pending)= File::Tail::select(undef,undef,undef,$timeout,@files);

                     unless ($nfound)
                     {
                                print "Nothing to print \n"; 
                     } 
                     else 
                    {
                                 foreach(@pending)
                                {
                                      my $line = $_->read;
                                       if ($line =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,5} -> (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})/)

                                        tie *STDOUT ref $txt1, $txt1;
                                        print $_->{"input"}."(".localtime(time).") IP:$1 PORT:$2\n"; ;
                                }
                       }
             }
}
}

The result for print $_->{"input"}."(".localtime(time).") IP:$1 PORT:$2\n"; matching the condition from here.

Mar 30 01:49:57 2011) 03/30-01:49:50.607858 119.40.116.196:80 -> 192.168.242.133:34628
TCP:34628-80 (Wed Mar 30 01:49:57 2011) TCP TTL:128 TOS:0x0 ID:34869 IpLen:20 DgmLen:40
TCP:34629-80 (Wed Mar 30 01:49:57 2011) 03/30-01:49:51.309716 119.40.116.196:80 -> 192.168.242.133:34629
UDP:41415-53 (Wed Mar 30 01:49:57 2011) 03/30-01:49:47.220999 192.168.242.2:53 -> 192.168.242.133:41415
UDP:44705-53 (Wed Mar 30 01:49:57 2011) 03/30-01:49:47.427011 192.168.242.2:53 -> 192.168.242.133:44705
UDP:50539-53 (Wed Mar 30 01:49:57 2011) 03/30-01:49:47.213455 192.168.242.2:53 -> 192.168.242.133:50539
 
Your subroutine never returns to the Tk event loop.

You'll need to add
Code:
$mw->update;
inside the while loop to refresh the text widget.

--
Kordaff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top