Operating System - HP-UX
1836878 Members
1712 Online
110111 Solutions
New Discussion

Telnet whith Automatic logon

 
SOLVED
Go to solution
Ivan Mariuz
Frequent Advisor

Telnet whith Automatic logon

Hello,

How can I can do to use telnet to remote host (cisco router) using automatic username and password. for exemple:
telnet username@password host

10 REPLIES 10
Ravi_8
Honored Contributor

Re: Telnet whith Automatic logon

Hi,

For systems you can use ssh
To login to Cisco router, i don't think you can use ssh
never give up
T G Manikandan
Honored Contributor

Re: Telnet whith Automatic logon

you can do something like

#!/bin/sh
(sleep 5
echo
sleep 5
echo
sleep 5
echo ls
sleep 5
echo exit) |telnet


YOu can do things better with PERL.
Wait until people like Procura replies.
Ivan Mariuz
Frequent Advisor

Re: Telnet whith Automatic logon

Hi, I try the script, but it don't works, the error was: "Connection closed by foreign host." I think The telnet program connects to the remote host but it completely ignores any commands you pipe to it. That's because the telnet program reads it input only from the terminal and not from standard input.
T G Manikandan
Honored Contributor

Re: Telnet whith Automatic logon

connection will be closed by the router if the password is wrong three times


Just modify as

#!/bin/sh
(sleep 5
echo
sleep 5
echo exit) |telnet

Ivan Mariuz
Frequent Advisor

Re: Telnet whith Automatic logon

The error is the same, The password are correct.
Rainer von Bongartz
Honored Contributor
Solution

Re: Telnet whith Automatic logon

you should use expect as a script language for this kind of interaction:

expect can be downloaded from software.hp.com

expect comes from :

http://expect.nist.gov/

Take a look there

Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Shannon Petry
Honored Contributor

Re: Telnet whith Automatic logon

You cant do this by normal scripting means. The input value will not be read from your script as the telnet prompt will stop the script.

You need to get a program called expect, which will allow you to script where waiting for stdin.

Regards,
Shannon
Microsoft. When do you want a virus today?
Rodney Hills
Honored Contributor

Re: Telnet whith Automatic logon

If you want to try perl, you can download a the "Net::Telnet::Cisco" module that makes interacting much easier. Here is a sample where I inquiry multiple cisco boxes for "arp" info-

use Net::Telnet::Cisco;
@swlist=(1,11..16,18,19,20,22,30);
%nouse=(1,1,18,1,15,1,30,1);
# 18,19 can not be telnet'd into from hpux?
foreach $ip4 (@swlist) {
next if $nouse{$ip4};
$ip="172.16.0.$ip4";
my $cs = Net::Telnet::Cisco->new( Host => $ip );

if ($ip4 eq "1") {
$cs->login( 'login', 'apasswd' ); # Do PIX firewall
$ok=$cs->enable("apasswd2"); # enable priv mode
my @cmd_output = $cs->cmd( 'no pager' ); # Turn off paging
} else {
$cs->login( 'login', 'apasswd3' ); # Do reg switch
my @cmd_output = $cs->cmd( 'terminal length 0' ); # Turn off paging
}

# Execute a command
@cmd_output = $cs->cmd( 'show tech-support' );
map s/^/$ip4>/, @cmd_output;
print @cmd_output;

$cs->close;
}


HTH

-- Rod Hills
There be dragons...
Chris Vail
Honored Contributor

Re: Telnet whith Automatic logon

Along with Ravi, I strongly urge you to use secure shell. Installed properly, your system won't be challenged for a password, and the whole conversation is encrypted using public/private keying. Telnet is NOT secure; it sends passwords unencrypted.
You can get the secure shell depot for free from software.hp.com. I wrote a document on how to implement it, which I've attached (it seems to be popular).
Ivan Mariuz
Frequent Advisor

Re: Telnet whith Automatic logon

Hi all, I resolve my problem using EXPECT.

My script:

#!/bin/sh
# exec expect "$0" ${1+"$@"}
set host [lindex $argv 0]
set login [lindex $argv 1]
set password [lindex $argv 2]
spawn telnet $host
expect "Username:"
send "$login\r"
expect "Password:"
send "$password\r"
interact

Thanks for all...
Ivan