'''
Created on 2011-8-3

@author: flyfox
'''
# -*- coding: utf-8 -*-
import telnetlib

HOST = "10.16.9.134" 
user = "root"
password = "password"

commonds = ["ls -l", "pwd", "who", "uname -a", "ifconfig -a"]

tn = telnetlib.Telnet(HOST) 

tn.read_until("ogin: ")
tn.write(user + "\r\n") 
if password:
    tn.read_until("assword: ")
    tn.write(password + "\r\n")

for commond in commonds:
    print(commond),
    tn.write(commond + "\r\n")
   

tn.write("exit\r\n")
print tn.read_all()
#print(tn.read_eager())
#print(tn.read_lazy())
#print(tn.read_very_eager())
#print tn.read_all()
tn.close()
print("Finish!")

 

 


 

没有登录不能评论