473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

any telnetlib equivalent in Python for rlogin?

Dear all,

I recently came across a Python program which used "telnetlib" to automate
things in the several unix machines in our local networks; I attached the
script as follows;

I wonder if it is possible to have the equivlent libary for "rlogin" in
Python? Because our local networks support only SSH or RLOGIN. This script
used Telnet so it could not be used in our local networks;

Considering I am quite new to Python, is there any way that I can easily
change this program to be used on "rlogin"? For example, is there a library
called "RLOGIN" that I can simply use self.tn = tn =
rloginlib.Rlogin(self.host), or something like that?

Thanks a lot,

-Walala

----------------------------------------------------------
import telnetlib
self.tn = tn = telnetlib.Telnet(self.host)
tn.read_until("login: ")
tn.write(self.username + "\n")
tn.read_until("Password: ")
tn.write(self.password + "\n")

# XXX: how to know whether login is successful?
tn.read_until(self.username)
#
Jul 18 '05 #1
2 4728
On Tue, 2003-11-11 at 04:22, walala wrote:
Dear all,

I recently came across a Python program which used "telnetlib" to automate
things in the several unix machines in our local networks; I attached the
script as follows;

I wonder if it is possible to have the equivlent libary for "rlogin" in
Python? Because our local networks support only SSH or RLOGIN. This script
used Telnet so it could not be used in our local networks;

Considering I am quite new to Python, is there any way that I can easily
change this program to be used on "rlogin"? For example, is there a library
called "RLOGIN" that I can simply use self.tn = tn =
rloginlib.Rlogin(self.host), or something like that?

Thanks a lot,

-Walala

Walala,

There is no standard ssh or rlogin module in the python standard library
I guess twisted has both (a quick google for twisted python could tell
you).

You don't mention what platform you are running on but if it's a *nix
then you could use pexpect (again google will tell you where to find
pexpect) to 'simulate' ssh like so:-
import pexpect
import sys
import re
import os

PROMPT = "\$|\%|\>"
class SSH:
def __init__(self, user, password, host):
self.child = pexpect.spawn("ssh %s@%s"%(user, host))
i = self.child.expect(['assword:', r"yes/no"], timeout=120)
if i==0:
self.child.sendline(password)
elif i==1:
self.child.sendline("yes")
self.child.expect("assword:", timeout=120)
self.child.sendline(password)
self.child.expect(PROMPT)
def command(self, command):
"""send a command and return the response"""
self.child.sendline(command)
self.child.expect(PROMPT)
response = self.child.before
return response

def close(self):
"""close the connection"""
self.child.close()
if __name__=="__main__":
import getpass
password = getpass.getpass("Password: ")
ssh = SSH("RemoteUsername", password, "RemoteHost")
print ssh.command("pwd")

Cheers
Martin

--
Martin Franklin <mf********@gatwick.westerngeco.slb.com>
Jul 18 '05 #2
"walala" <mi*****@yahoo.com> wrote in message
news:bo**********@mozo.cc.purdue.edu...
Dear all,
Considering I am quite new to Python, is there any way that I can easily
change this program to be used on "rlogin"? For example, is there a library called "RLOGIN" that I can simply use self.tn = tn =
rloginlib.Rlogin(self.host), or something like that?


Yes: replicate the public interface of telnetlib, and use the rlogin
protocol instead of the telnet protocol behind-the-curtain. Much of the
telnetlib public interface will be redundant, because these protocols don't
have many escape or control characters, and hence do very little data
cooking.

As for the behind-the-covers implementation, you can either go expect-like
and communicate with an rlogin/ssh subshell through os.popen2/3, or
reimplement an rlogin/ssh client in Python. Reimplementing the rlogin
client looks pretty easy--its a simple protocol (rfc1282). Reimplementing
ssh is _far_ more ambitious--I think communicating with a subshell is
probably a better idea for that.

It seems odd to me that your network supports rlogin but not telnet--rlogin
is iirc far more insecure because of the .rhosts nonsense. I think ssh is
certainly a better choice here, even though using it will be messier.
--
Francis Avila

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ÕÅÖ¾Ã÷ | last post by:
code below cannt work import getpass import sys import telnetlib import select tn = telnetlib.Telnet() print tn.open("162.105.31.222",23)
2
by: John Abel | last post by:
I have written a script that makes a telnet connection, runs various commands, and returns the output. That was the easy bit :) However, to close the session, I need to send ^] followed by quit. ...
1
by: Stephen Ferg | last post by:
I'm trying to use telnetlib to run a Java program on a remote server. I'm having strange problems, and I'm wondering if anyone might be able to help. I have two UNIX servers, A and Z. I have...
3
by: Mike Monaghan | last post by:
I'm rather new to python but a long time programmer. I think I've covered my bases so I hope this isn't somthing obvious. I'm running ActiveState PythonWin 2.3.2 (#49, Nov 13 2003, 10:34:54) ...
3
by: Svha | last post by:
Greetings I'd like to do some tweaks on a telnet session as I have no control over the server side what so ever. However I cannot correctly negotiate a telnet connection to the server. I've...
1
by: Bryan Hesters | last post by:
I'm trying to build a Win32 application that will log into a PBX via RLogin. I'm not very versed in protocol programming and all the examples I can find on the internet are either linux based (GNU...
3
by: Wojciech Halicki-Piszko | last post by:
How to know if connection is active after telnetlib.Telnet.open(host,port)?
4
by: vercingetorix52 | last post by:
I'm trying to use a python script to access an embedded computer running linux and connected via a crossover ethernet cable using the following script... ....and I realize the username and...
1
by: dudds | last post by:
Hi Guys, I just started learning Python a couple of days ago and to put some of what I learnt into practice. As such I thought I might try and write a simple program (based on examples I had...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.