1. 程式人生 > >Learning Python telnet.lib

Learning Python telnet.lib

inpu output code get () use enter you all

#!/usr/bin/env python import getpass import sys import telnetlib HOST = "X.X.X.X" user = raw_input("Enter your telnet username: ") password = getpass.getpass() tn = telnetlib.Telnet(HOST) tn.read_until("username: ") tn.write(user + "\n") if password: tn.read_until("password: ") tn.write(password + "\n") tn.write("terminal length 0\n") tn.write("sh run | sec hostname") tn.write("exit\n") output_*** = tn.read_all()

Learning Python telnet.lib