GUI script

Hi. Iam having trouble with this GUI script. Well the script works fine but when i enter the IP and hit ping it pull up ping program itself.I want it to take the Number i entered and ping that number.
Someone please tell me what to do.

This is for PERL and on a Win98 machine

Script below#util to ping ip.
#with Tk gui
#version 1.0
#-colinok

use Tk;
use Tk::LabEntry;

#make the main window

$top = new MainWindow;

#make a form box

$l=$top->LabEntry(-label => "Enter a IP Address: ",
-textvariable => \$foo,
)->pack;

#make a button

			  $top->Button\(-text => 'Ping', 
          -command => $main1
          \)->pack;

MainLoop;

#take ip and ping it

$foo = ($ping, $main1);

system ("ping $ping");

I know you've had trouble with my scripts in the past, but this one worked on my Win98 system with the name "ping.pl" - it should work on yours! The ping results appear in the MSDOS text box, here we go:

#!/perl/bin/perl

 use Tk;

 $mw = MainWindow -> new\(\); 
 $label = $mw -> Label\(-text => 'Enter IP / Hostname'\) -> pack;
 $entry = $mw -> Entry\(\) ->pack; 

 $mw->Button\(-text => 'Ping', 
               -command => sub\{ping_Host\(\)\}
               \)->pack;
 MainLoop;

 sub ping_Host \{
     \# Get hostname/IP address
 $txt = $entry -> get\(\); \# Get the input
 system\("ping $txt"\);
 \}

Thanks. Its perfect. What we need to do now is get it to run the dos window in the gui its self! get me?? so when u hit ping, the gui gets longer and a white aera appears below and the pinging happens there. About your scripts not working for me, thats all my fault! i do stupid thing,, e.g rename script, i took the "code: --------------" part and that brought up loads of errors,

So thanks again.

-perleo

Perleo,

Your wish is my command! I have also added a vertical scrollbar to make your life easier. Every time you ping a machine, the details get added to the box. You can change the size of the box (check the width and height settings in the code below) - one last thing, if you can afford it, get a copy of "Mastering Perl/Tk - O'reilly"; it's what I've been using to help me with your code. Anyway, here's the answer:

#!/perl/bin/perl

use Tk;

$mw = MainWindow -> new();
$label = $mw -> Label(-text => 'Enter IP / Hostname') -> pack;
$entry = $mw -> Entry() -> pack;

$mw->Button(-text => 'Ping',
-command => sub{ping_Host()}
)->pack;

# pack it seperately so that they are side by side
$scrollbar = $mw -> Scrollbar();
$text = $mw -> Text(-height => 20, -width => 50, -yscrollcommand => ['set' => $scrollbar]);
$scrollbar -> configure(-command => ['yview' => $text]);

$scrollbar -> pack(-side => 'right', -fill => 'y');
$text -> pack(-side => 'left', -fill => 'both');

MainLoop;

sub ping_Host {
# Get hostname/IP address
$txt = $entry -> get(); # Get the input
$result =`ping $txt`;
#place results into text box
$text -> insert('end', "$result");
}

MAN YOUR GOOD!!!! Thanks. Iam actually flying to Los Angeles in 12 hours time! (its 7pm in Tipperary , in Ireland) and iam flying out at 7:30am. Cant wait to go. Iam getting Running Linux by O'Reilly so i'll get that one as well.And iam only 14 ! :slight_smile:

Thanks

And happy x-mas.!

Have a great time in Los Angeles!

And - Happy XMAS to you too!