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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GUI Port Scanner with socket problem

Status
Not open for further replies.

Raenius

Programmer
Oct 14, 2003
77
NL
Hi all,

I am having two problems:

1. I can't get the output of the scan to my right text frame :S Have no clue how to do this
2. Everything is quite slow, can I make this faster?

Here is my code:

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( "DCP Portscanner");

$main->Label( - text=>"Version 1.0 by Patrick de Kok",
- 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 => '100',
-width => '100',
-background=>'white',
-borderwidth => 2,
- relief =>'groove',
);
MainLoop;

# Functions

sub onQuit
{
exit;
}


sub onScan
{

$| = 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

tie *STDOUT, $OutputText;

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: $!"
{
print "Succesfully connected to port: $port\n";
}
else
{
print "Could not connect to port: $port\n";
}
}
}

"Free will...is an illusion"
 
Not sure what you want to do. I'll take a stab, and say you want to display "Successfully....$port" or "Could not connect to port: $port" underneath Scan Result. If so....

my $rf = $main->Frame( - relief =>'groove',
- borderwidth => 2,
)
->pack;
$rf->Label(-text => " Scan result",
-width => "20"
)->pack;

my $OutputText = $rf->Scrolled("Text",
-scrollbars => "se",
-height => '20',
-width => '50',
-background=>'white',
-borderwidth => 2,

- relief =>'groove',
)->pack();

and use

$OutputText->insert("end",$STRING_TO_INSERT_INTO_TEXT_BOX);

For what you want ot display in the textbox
 
FYI:
$main->update();

Will update the Tk window after each insertion to the text box.
 
For some reason, unknown to me I cannot use the Scroll function. This will fuction without this right?

I will try this asap and get back to you! Thanks for your help so far!

- Raenius

ps. h011ywood you were right about what I wanted to do!

"Free will...is an illusion"
 
Oke I tried it and unfortunately it did not work:

This is my window declaration:

my $rf = $main->Frame( - relief =>'groove',
- borderwidth => 2,
)
->pack
->Label(-text => " Scan result",
-width => "20"
)->pack;
my $OutputText = $rf->Text( -height => '20',
-width => '50',
-background=>'white',
-borderwidth => 2,
- relief =>'groove',
);

These are the output stuff for testing:

my $output = "Succesfully connected to port: $port\n";
$OutputText->insert("end",$output); $main->update();

What am I doing wrong? ( I als o don't see a white box for the text, I'm supposed to rigth?With the white background parameter?

- a very confused Raenius



"Free will...is an illusion"
 
Your OutputText box never gets packed. Use this in place of your current $OutputText declaration.

my $OutputText = $rf->Scrolled("Text",
-scrollbars => "osoe",
-height => '20',
-width => '50',
-background=>'white',
-borderwidth => 2,
- relief =>'groove',
)->pack();
 
Perfect that works! Thanks a lot!

New problem is the Scrollbar error I get.

If I use the Scrolled("Text",
-scrollbars => "osoe",

line then it gives me an error saying that I don't have addscrollbars.pm or something like that :(

- Raenius

"Free will...is an illusion"
 
What version of Perl, and PerlTk are you using? I tested this using ActiveState Perl 5.8 on Windows 2k.

 
Perl 5.8 on Windows XP with Tk version Tk-804.025_beta6...

Its really strange, I got also a stupid problem with another problem ( in my other thread) with a dialogbox not functioning here :S But thats another story ;-)



"Free will...is an illusion"
 
I still don't have a clue what is wrong :(

The script does exactly what I want...except for the Scrolled text part...

"Free will...is an illusion"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top