2014/01/04

使用python的 telnetlib對網路設備進行一些自動化的操作
範例如下


import telnetlib

HOST = "1.1.1.1"

tn = telnetlib.Telnet(HOST)

tn.read_until("Password: ")
tn.write("12345\n")
tn.read_until("cc>")
tn.write("en\n")
tn.read_until("Password: ")
tn.write("12345\n")

tn.write("sh flash\n")
tn.write("exit\n")
print tn.read_all()

http://blog.johnsonlu.org/category/programe/pythin/
http://docs.python.org/2/library/telnetlib.html

沒有留言: