#!/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()
原文地址:http://blog.51cto.com/blade20/2147141
时间: 2024-11-08 23:40:34