any telnetlib equivalent in Python for rlogin?

Discussion in 'Python' started by walala, Nov 11, 2003.

  1. walala

    walala Guest

    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)
    #
     
    walala, Nov 11, 2003
    #1
    1. Advertising

  2. 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 <>
     
    Martin Franklin, Nov 11, 2003
    #2
    1. Advertising

  3. "walala" <> wrote in message
    news:bopo66$rev$...
    > 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
     
    Francis Avila, Nov 12, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan Hesters

    Rlogin Library?

    Bryan Hesters, Oct 9, 2003, in forum: C++
    Replies:
    1
    Views:
    415
    Thomas Matthews
    Oct 9, 2003
  2. Lukas Schnieper

    Problems with rlogin and executing a script

    Lukas Schnieper, Oct 1, 2003, in forum: Python
    Replies:
    2
    Views:
    584
    Richard
    Oct 1, 2003
  3. Martin Franklin
    Replies:
    0
    Views:
    378
    Martin Franklin
    Oct 1, 2003
  4. David H
    Replies:
    0
    Views:
    494
    David H
    Dec 3, 2004
  5. Jean-Louis Leroy

    Rlogin client?

    Jean-Louis Leroy, Nov 3, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    125
    Jean-Louis Leroy
    Nov 5, 2004
Loading...

Share This Page