Connection Telnet en Perl

From Tuxunix
Jump to: navigation, search

Exemple


tuxedoHome:/tmp# /root/cgiPerl.pl 
Content-Type: text/html; charset=ISO-8859-1
total 91832
drwxr-xr-x 46 pierrot pierrot     4096 2008-01-23 21:07 .
drwxr-xr-x  3 root    root        4096 2007-01-15 21:31 ..
drwx------  2 pierrot pierrot     4096 2007-01-21 21:19 amsn_received
... 

Code


   1.#!/usr/bin/perl
   2.       
   3.use strict;
   4.use Net::Telnet;
   5.use CGI qw/:standard :html3 :netscape escape unescape/;
   6.use CGI::Carp qw/fatalsToBrowser/;
   7.       
   8.my $username="xxxxx";
   9.my $passwd="xxxxx";
  10.my $HOST="127.0.0.1";
  11.print header;
  12.my $t = new Net::Telnet (Timeout=>undef) or die "Cant connect:$!";
  13.$t->open($HOST);
  14.$t->login($username, $passwd);
  15.my @lines = $t->cmd("ls -la");
  16.print join(" ", @lines);