1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #!/usr/bin/perl
use warnings;
use strict;
use Tk; # Appel du module Tk
use Net::Telnet;
my $cmd="";
my $prompt="";
my $long_prompt="";
my @result="";
my $telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die');
my $fenetre = new MainWindow(-title => 'Telnet',-background => 'white',);
$fenetre->geometry("1000x700");
my $bouton = $fenetre->Button(-text => 'Connexion',-command => [\&connexion,],,)->pack();
$bouton->place(-x => 250, -y => 50 );
my $texte = $fenetre->Text( )->pack( );
$texte->place(-x => 100, -y => 200 );
$texte->bindtags([reverse $texte->bindtags]);
$texte->bind("<Return>",[\&commande]);
$texte->bind("<Tab>",[\&tab]);
sub connexion
{
$telnet->open('10.57.72.12');
@result =$telnet->waitfor('/authentication\b/');
$texte->insert('end',(@result));
$texte->insert('end',($result[1]));
$telnet->print('');
$telnet->waitfor('/Username:$/i');
$telnet->print('admin');
$telnet->waitfor('/Password:$/i');
$telnet->print('motdepasse');
@result=$telnet->waitfor('/login/');
$texte->insert('end',(@result));
$texte->insert('end',($result[1]));
$telnet->print('');
@result=$telnet->waitfor('/.*[\$>\]\%] *$/'); # détection prompt
$texte->insert('end',@result);
$texte->insert('end',$result[1]);
$texte->see('end');
$prompt =$texte->get("end -1 lines" ,"end");
$long_prompt=length($prompt) -1;
$texte->focus;
}
sub tab
{
$cmd =$texte->get("end -1 lines + $long_prompt chars","end - 1 chars"); #détermination commande
$telnet->print($cmd."\t");
sleep(1);
@result = $telnet->waitfor('/More ----|.*[\$>\]\%] *$/'); # détection prompt
my$result=$result[-2];
chop $result;
$texte->insert('end',"\n".$result);
$texte->focus;
$texte->see('end');
Tk->break;
}
sub commande
{
$cmd =$texte->get("end -1 lines + $long_prompt chars","end"); #détermination commande
$telnet->print(($cmd));
sleep(1);
@result = $telnet->waitfor('/More ----|.*[\$>\]\%] *$/'); # détection prompt
my$result=$result[-2];
chop $result;
$texte->insert('end',"\n".$result);
$texte->see('end');
$prompt =$texte->get("end -1 lines","end" );
$long_prompt=length($prompt)-1;
Tk->break;
}
MainLoop; # |
Partager