Automated telnet -and yes!! I am crazy.

I have several machines on an internal network that is DMZ and some level of promisquiety is allowed.

Is it possible to write a script that can automatically feed a Telnet prompt Username and Password ?
Username is easy but password is a bit troublesome.

Please present a script which will when executed log you in if you have password and username as variables in the script.
LVL 1
dryzoneAsked:
Who is Participating?
 
jlevieConnect With a Mentor Commented:
If you really want to do this with telnet the following will work. You'll need to edit the file and change "my-name" and "my-passwd" to the user name and password on the remote system. Also you'll want to make the file owned by yourself and set it to mode 700.

#!/usr/bin/expect --
# Simple script to open a telnet session on a remote host. The script will
# exit when you log out of the remote. It expects the host name on the
# command line, e.g., "this-script remote-server".
#
set host [lindex $argv 0]
set timeout 60
spawn telnet $host
expect "ogin:"
send "my-name\r"
expect "assword:"
send "my-passwd\r"
interact

If you were getting a password prompt using ssh then something didn't get set up properly. First of all you need to be using a recent copy of OpenSSH that supports SSH 2. Then on the local system execute:

illusion> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jlevie/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jlevie/.ssh/id_rsa.
Your public key has been saved in /home/jlevie/.ssh/id_rsa.pub.
The key fingerprint is:
9a:fa:78:ac:....
illusion>

At the passphrase prompts just hit return. Add the contents of .ssh/is_rsa.pub to ~/.ssh/authorized_keys2 on the remote system. That's easily done after copying the file to the remote with:

remote> cat ip_rsa.pub >>.ssh/authorized_keys2

Then from the local system just execute "ssh remote". You won't get a  passwd request and will be logged in. Another nice thing about this is that it also works for scp and when using ssh to execute commands on the remote... Much more powerful than using an expect script to establish a telnet session.
0
 
superschlonzCommented:
Im using expect (http://expect.nist.gov/) for things like that.
It's a TCL/Tk interpreter with some added functionality for running an controlling processes.
0
 
jlevieCommented:
Why bother with that. Given the description of what you have and want to do it would make just as much sense to configure the systems for rlogin or ssh access using rhosts. In that case no password would be required for those users/machines permitted access that way.

Personally I'd generate a keypair with ssh-keygen (with no passphrase) and place the public key in .ssh/authorized_keys2 on the remote system. That allows me to simply say "ssh remote-host" and be instantly logged in without having to supply a password. It's far more secure than using rhosts files or hosts.equiv and has the bonus of using an encrypted session.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
dryzoneAuthor Commented:
jleve.
Yes I am running SSH on my firewall for whenever I am outside.
However, the ssh behaviour as you describe could never be implimented. Passwords were always required. You are right about using ssh, but it is slow compared to telnet  and I am in a DMZ.
sure rlogin.......still needs a password.

Both superschlonz and jleve.
Give me a script which I enter username and password and when I run it I am logged in and you have the points.
0
 
dryzoneAuthor Commented:
Looked good but did not work.
Expect is in /usr/bin so that works.
HGowever the script failed.


[Lht@gateway Lht]$ ./loginhelper
spawn telnet
usage: telnet [-l user] [-a] host-name [port]
send: spawn id exp4 not open
    while executing
"send "Lht\r""
    (file "./loginhelper" line 10)
[Lht@gateway Lht]$
0
 
jlevieCommented:
The script expects the host name of the remote system as an argument, so execute it as "loginhelper remote-name". My presumption was that you'd have the same name and password on each of the DMZ systems and you could then use one script and specify the system on the command line.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.