im making a script with net::snmp and wanted to output the results on a textbox so after reading a while i managed to create a gui with a textbox and a button to start collecting info of routers. the problem i ran into is that im usync async calls with snmp and the gui simply freezes, it must be, either by the snmp_dispatcher function or because of the timeout. So after a while reading i saw someone suggested the DoOneevent; and used with not much luck. Is there a way for this script to stop freezing?? oh btw, do you know of any widget that might format the output to the textbox like this functions does?? "format STDOUT =" heres the code.
#!/usr/bin/perl -w use warnings 'all'; use strict; use Net::SNMP qw(snmp_dispatcher oid_lex_sort); use Tk; use Tk::LabEntry; my $pstme = localtime(); my $startip; my $endip; my $community; my $maxwork; my $mw = MainWindow->new(-width=>'300',-height=>'600'); #$mw->geometry("350x100"); $mw->resizable( 0, 0 ); $startip = '1.1.1.1'; $endip = '1.1.1.255'; $community = 'public'; $maxwork = '20'; my $ipmwf = $mw ->Frame ( -borderwidth=>3,-relief=>'flat' ) -> pack(-s +ide=>'top',-expand=>0,-fill=>'x'); my $from = $ipmwf->LabEntry(-borderwidth=>2,-background=>'White',-reli +ef=>'sunken', -label => "IP range: ", -labelPack=>[-side=>'left',-anchor=>'n' ], -width => 15, -textvariable => \$startip, )->pack(-side=>'left',-anchor=>'nw',-expand=>0,-fil +l=>'x',-pady=>3); my $to = $ipmwf->LabEntry(-borderwidth=>2,-background=>'White',-relief +=>'sunken', -label => " to ", -labelPack=>[-side=>'left',-anchor=>'n' ], -width => 15, -textvariable => \$endip, )->pack(-side=>'left',-anchor=>'nw',-expand=>0,-fil +l=>'x',-pady=>3); my $othfm = $mw ->Frame ( -borderwidth=>3,-relief=>'flat' ) -> pack(-s +ide=>'top',-expand=>0,-fill=>'x'); my $commst = $othfm->LabEntry(-borderwidth=>2,-background=>'White',-re +lief=>'sunken', -label => "Community String: ", -labelPack=>[-side=>'left',-anchor=>'w' ], -width => 15, -textvariable => \$community, )->pack(-side=>'left',-anchor=>'nw',-expand=>0,-fil +l=>'x',-pady=>3); my $inpthr = $othfm->LabEntry(-borderwidth=>2,-background=>'White',-re +lief=>'sunken', -label => "Threads: ", -labelPack=>[-side=>'left',-anchor=>'w' ], -width => 4, -textvariable => \$maxwork, )->pack(-side=>'left',-anchor=>'nw',-expand=>0,-fil +l=>'x',-pady=>3); my $strtbtn = $ipmwf->Button ( -overrelief=>'raised',-relief=>'raised' +,-text=>'Start Scan', -compound=>'none',-state=>'normal',-command => +\&Strtscan ) ->pack(-side=>'left',-padx=>8); my $infm = $mw ->Frame ( -borderwidth=>3,-relief=>'flat' ) -> pack(-si +de=>'top',-expand=>0,-fill=>'x'); my $infor = $infm -> Scrolled ( 'Text', -relief=>'sunken', -scrollbars=>'se', -wrap=>'none', -state=>'normal' ) -> pack(-side=>'left'); MainLoop(); { sub Strtscan { my $state = $strtbtn->cget('-state'); $strtbtn-> configure('-state' => 'disabled'); $strtbtn-> update; my $startip = $from->get(); my $endip = $to->get(); my $community = $commst->get(); my @ip_start = split(/\./,$startip); my @ip_end = split(/\./,$endip); { my $conter=0; my($i,$j,$k,$l); for ($l="$ip_start[0]";$l<="$ip_end[0]";$l++){ for ($i="$ip_start[1]";$i<="$ip_end[1]";$i++){ for ($j="$ip_start[2]";$j<="$ip_end[2]";$j++){ for ($k="$ip_start[3]";$k<="$ip_end[3]";$k++){ my ($session,$error)=Net::SNMP->session(-hostname=>"$l.$i.$j.$ +k",-version=>'snmpv2c',-nonblocking=>1,-community=>"$community",-time +out=>2,-retries=>1); if (defined($session)) { my $result=$session->get_request( -varbindlist=>['1.3.6.1.3.83.1.1.4.0','1.3.6.1.2.1.2.2.1.6 +.2'], callback=>[\&getms,$session,"$l.$i.$j.$k"] ); }else{ print "Session not defined! $error\n"; }; }; DoOneEvent(); snmp_dispatcher(); }; }; }; }; $strtbtn-> configure('-state' => 'active'); $strtbtn-> update; }; }; { sub getms { my $obj = shift; my $session = shift; my $ip = shift; if (!defined($obj->var_bind_list)) { $infor->insert('end',"$ip SNMP Error $obj->error() \n"); DoOneEvent(); return; }; }; };

In reply to perl/tk script freezes by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.