#!/usr/bin/python import sys, telnetlib, getpass newipaddr = '192.168.1.2' swlogin = 'root' swpass = getpass.getpass() tn = telnetlib.Telnet(newipaddr) tn.read_until("name") tn.write(swlogin+'\n') tn.read_until("word") tn.write(swpass+'\n') tn.write("ls\n") tn.write("exit\n") print tn.read_all()