Beste Tweakers,
Na een hoop gezocht te hebben heb ik toch niet het antwoord gevonden op dit simpele toch frusterende probleem. Ik heb een portscanner met gui geschreven en het maakt gebruik van sockets. Nu komt de output van het programma dus wel in de commandline maar niet in het rechterframe van het scherm. Heeft iemand een idee hoe ik het daar kan krijgen, de code hieronder heb ik op dit moment:
use IO::Socket;
# DCP Log Analyser GUI t
#use strict;
use Tk;
use Tk::OptionMenu;
use Tk::Frame;
use Tk::TextUndo;
use Tk::Text;
use Tk::Scrollbar;
use Tk::Menu;
use Tk::Menubutton;
use Tk::Adjuster;
use Tk::Dialogbox;
my $main;
my $menubar;
my $file_menu;
$main = MainWindow->new();
$main->geometry('400x300');
$main->title( "Portscanner");
$main->Label( - text=>"Version 1.0 by Raenius",
- relief => "raised") # Create label and pack bottom
->pack ( - side => 'bottom',
- fill => "x");
$menubar = $main->Frame( - relief => "raised",
- borderwidth => 2)
->pack ( - anchor => "nw",
- fill => "x");
$file_menu = $menubar->Menubutton( - text => "File",
- underline => 1,
- menuitems => [
[ Button => "Scan!", -command => \&onScan ],
[ Button => "Quit", -command => \&onQuit ]
]
)
-> pack( - side => "left");
$file_menu = $menubar->Menubutton( - text => "Help",
- underline => 1,
- menuitems => [
[ Button => "About", -command => \&onAbout ],
[ Button => "Helpfile", -command => \&Print ],
]
)
-> pack( - side => "left",
- fill => "x");
#This is the main frame for the program
my $mainframe = $main->Frame
->pack( - side => "left",
- fill => "both");
my $first = $mainframe->Frame( - relief =>'groove',
- borderwidth => 2,
)
->pack
->Label(-text => " Input Target IP:",
-width => "20"
)->pack(-side => 'left');
my $second = $mainframe->Entry( - relief =>'groove',
- borderwidth => 2
)
->pack;
$mainframe->Button( - text => 'Execute!',
- command => sub { my $input = $second->get;
&onScan($input);
}
)
->pack;
my $rf = $main->Frame( - relief =>'groove',
- borderwidth => 2,
)
->pack
->Label(-text => " Scan result",
-width => "20"
)->pack; # (-side => 'left')
my $OutputText = $rf->Text( -height => '20',
-width => '50',
-background=>'white',
-borderwidth => 2,
- relief =>'groove',
);
#my $OutputText = $rf->Scrolled("Text",
# -scrollbars => "se",
# -height => '20',
# -width => '50',
# -background=>'white',
# -borderwidth => 2,
# -relief =>'groove',
# )->pack();
MainLoop;
# Functions
sub onQuit
{
exit;
}
sub onScan
{
my $output = "Succesfully connected to port: $port\n";
$OutputText->insert("end",$output);
$rf->update;
# THIS DOES NOT WORK!
$| = 1; # auto buffer flush
$host = shift;
@ports = (21..25,79,80,110,113,119,135,139,143,389,443,445,1002,1024..1030,1720,5000); # a list of ports
#print "Attemping to connect to ports on host: $host\n";
foreach my $port (@ports)
{
if(my $sock = new IO::Socket::INET (
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => '1')) # or die print "Socket Error: $!"
{
my $output = "Succesfully connected to port: $port\n";
$OutputText->insert("end",$output);
$rf->update;
print "$port connected\n";
}
else
{
my $output = "Could not connect to port: $port\n";
$OutputText->insert("end",$output);
$rf->update;
print "could not connect\n";
}
}
}
Alvast bedankt voor enige reacties.
Vriendelijke groet,
Raenius
Na een hoop gezocht te hebben heb ik toch niet het antwoord gevonden op dit simpele toch frusterende probleem. Ik heb een portscanner met gui geschreven en het maakt gebruik van sockets. Nu komt de output van het programma dus wel in de commandline maar niet in het rechterframe van het scherm. Heeft iemand een idee hoe ik het daar kan krijgen, de code hieronder heb ik op dit moment:
use IO::Socket;
# DCP Log Analyser GUI t
#use strict;
use Tk;
use Tk::OptionMenu;
use Tk::Frame;
use Tk::TextUndo;
use Tk::Text;
use Tk::Scrollbar;
use Tk::Menu;
use Tk::Menubutton;
use Tk::Adjuster;
use Tk::Dialogbox;
my $main;
my $menubar;
my $file_menu;
$main = MainWindow->new();
$main->geometry('400x300');
$main->title( "Portscanner");
$main->Label( - text=>"Version 1.0 by Raenius",
- relief => "raised") # Create label and pack bottom
->pack ( - side => 'bottom',
- fill => "x");
$menubar = $main->Frame( - relief => "raised",
- borderwidth => 2)
->pack ( - anchor => "nw",
- fill => "x");
$file_menu = $menubar->Menubutton( - text => "File",
- underline => 1,
- menuitems => [
[ Button => "Scan!", -command => \&onScan ],
[ Button => "Quit", -command => \&onQuit ]
]
)
-> pack( - side => "left");
$file_menu = $menubar->Menubutton( - text => "Help",
- underline => 1,
- menuitems => [
[ Button => "About", -command => \&onAbout ],
[ Button => "Helpfile", -command => \&Print ],
]
)
-> pack( - side => "left",
- fill => "x");
#This is the main frame for the program
my $mainframe = $main->Frame
->pack( - side => "left",
- fill => "both");
my $first = $mainframe->Frame( - relief =>'groove',
- borderwidth => 2,
)
->pack
->Label(-text => " Input Target IP:",
-width => "20"
)->pack(-side => 'left');
my $second = $mainframe->Entry( - relief =>'groove',
- borderwidth => 2
)
->pack;
$mainframe->Button( - text => 'Execute!',
- command => sub { my $input = $second->get;
&onScan($input);
}
)
->pack;
my $rf = $main->Frame( - relief =>'groove',
- borderwidth => 2,
)
->pack
->Label(-text => " Scan result",
-width => "20"
)->pack; # (-side => 'left')
my $OutputText = $rf->Text( -height => '20',
-width => '50',
-background=>'white',
-borderwidth => 2,
- relief =>'groove',
);
#my $OutputText = $rf->Scrolled("Text",
# -scrollbars => "se",
# -height => '20',
# -width => '50',
# -background=>'white',
# -borderwidth => 2,
# -relief =>'groove',
# )->pack();
MainLoop;
# Functions
sub onQuit
{
exit;
}
sub onScan
{
my $output = "Succesfully connected to port: $port\n";
$OutputText->insert("end",$output);
$rf->update;
# THIS DOES NOT WORK!
$| = 1; # auto buffer flush
$host = shift;
@ports = (21..25,79,80,110,113,119,135,139,143,389,443,445,1002,1024..1030,1720,5000); # a list of ports
#print "Attemping to connect to ports on host: $host\n";
foreach my $port (@ports)
{
if(my $sock = new IO::Socket::INET (
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => '1')) # or die print "Socket Error: $!"
{
my $output = "Succesfully connected to port: $port\n";
$OutputText->insert("end",$output);
$rf->update;
print "$port connected\n";
}
else
{
my $output = "Could not connect to port: $port\n";
$OutputText->insert("end",$output);
$rf->update;
print "could not connect\n";
}
}
}
Alvast bedankt voor enige reacties.
Vriendelijke groet,
Raenius
http://www.catalogged.net/