On 5/16/07, a b <[EMAIL PROTECTED]> wrote:
Hello,
I am trying to telnet to all m/c for which i haven't set password(only root
is a valid user)
any body can telnet using root user
But when i try to access through perl it
<snip>
use warnings;
use Net::Telnet;

my $t = new Net::Telnet (Timeout => 10,Prompt => '/bash\$ $/');
my @line;
$t->open("host1");
$t->waitfor('/login:.*$/');
$t->print("root");
$forecast=$t->print("/usr/bin/ls");
print $forecast;


O/P : 1

OR

use warnings;
use Net::Ping;
use Net::Telnet;

my $t = new Net::Telnet (Timeout => 10,Prompt => '/bash\$ $/');
my @line;
$t->open("host1");
$t->login("root","");
$result=$t->cmd("/usr/bin/ls");
print $result;

O/P : timed-out waiting for password prompt at j.pl line 8



Close.

You do the login correctly in example 1, but then you use print to
issue the command. all that does is print the string "/usr/bin/ls\n"
to the remote terminal and return 1 to let you know the command
succeeded. If you want the output of the remote command, you need to
use cmd (in list context)

In example 2, you don't pass a password to login or waitfor one, so
you never login. You do, though, use cmd, which is what you want,
although you need list context:

$t->open("host1");
$t->waitfor('/login:.*$/');
$t->print("root");
my @forecast=$t->cmd("/usr/bin/ls");
my $scalar_forecast = join "", @forecast;
# or join'\n', I don't remember if cmd returns newlines or not

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to