2008年1月9日 星期三

[Python] Telnet example

import telnetlib

host="140.113.x.x"
user="jing"
passwd="xxxx"

com_array=["cd /home",
           "ls -la",
           "exit"]

tn = telnetlib.Telnet(host)
tn.set_debuglevel(2)

tn.read_until("login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(passwd + "\n")

for command in com_array:
        tn.write(command+'\n')
print tn.read_all()  # print the results
print "Job done!"

沒有留言:

張貼留言