telnetlib - Telnetlib 似乎没有传递 .write 命令
问题描述
我是这里的python新手,只是想学习一项新技能,所以请温柔:)
执行以下脚本后,我的脚本似乎创建了一个 telnet 会话,我可以看到 cisco 设备横幅,但在出现提示时未传递用户名/密码。
我尝试更改 tn.read_until() 和 tn.read_very_eager() 两者都不会触发脚本继续写入所需的输入。我还尝试强制将用户名和密码作为字节输入,并将 + '\n' 添加到我的写入函数中。我还使用 sleep 来通过一些额外的时间来等待横幅完成打印。
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')
'''
解决方案
推荐阅读
- python - 列表索引超出范围,但我不明白为什么
- c - 如何解决C中的动态内存分配错误
- android - (Kotlin) 文本字段的焦点
- mysql - 多个表上的多个 COUNT
- oracle - 为什么这里需要模式名称以及如何在没有它的情况下进行编译
- python - 有没有办法通过将字符串添加到 Python 中的另一个变量来调用变量?
- html - 为什么调整特定 svg 的大小不适用于 CSS
- excel - Open SharePoint file into desktop version of Excel
- reactjs - 根据函数返回的内容渲染组件
- python - 创建的新列的值不正确