我是一个Python新手,只是想学习一种新技能,所以请保持柔和:)
执行以下脚本后,似乎我的脚本创建了一个telnet会话,并且可以看到cisco设备横幅,但在出现提示时未传递用户名/密码。
我尝试更改tn.read_until()和tn.read_very_eager()都不会触发脚本继续写所需的输入。我还尝试强制将用户名和密码作为字节输入,以及在写函数中添加+'\ n'。我还用睡眠时间多了一些时间来等待横幅完成打印。
tldr:执行脚本时,我看到用户名提示,但不能超过此范围。
欢迎在这里提供任何帮助。
'''
from time import sleep
import telnetlib
from telnetlib import Telnet
from getpass import getpass
Username = input('please provide your username ')
password = getpass()
# f is the .txt document that lists the IP's we'll be using.
f = open('devicess.txt')
for line in f:
print ('Configuring Device ' + (line))
device = (line)
#open connection to variable
tn = telnetlib.Telnet(device)
#For those devices in the above list, connect and run the below commands
for device in f:
tn.expect('Username: ')
tn.write(Username)
tn.expect('Password: ')
tn.write(password)
tn.write('show ver')
print('connection established to ' + device)
tn.write('logout')
output = tn.read_all()
print(output)
print('script complete')
'''