any telnetlib equivalent in Python for rlogin?

Martin Franklin mfranklin1 at
Tue Nov 11 11:19:35 CET 2003

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 = tn =
> rloginlib.Rlogin(, or something like that?
> Thanks a lot,
> -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 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:
        elif i==1:
            self.child.expect("assword:", timeout=120)
    def command(self, command):
        """send a command and return the response"""
        response = self.child.before
        return response
    def close(self):
        """close the connection"""

if __name__=="__main__":
    import getpass
    password = getpass.getpass("Password: ")
    ssh = SSH("RemoteUsername", password, "RemoteHost")
    print ssh.command("pwd")


Martin Franklin <mfranklin1 at>

More information about the Python-list mailing list