如果我手动将ips放入列表中,脚本正在运行,如果我尝试从txt文件中读取它们,我会收到错误:gaierror:[Errno 11001] getaddrinfo failed
这是我的代码:
import telnetlib
from __future__ import with_statement
file = open('ips.txt', 'r')
HOST = file.readlines()
print HOST
user = "root"
password = "root"
for i in range(len(HOST)):
tn = telnetlib.Telnet(HOST[i])
tn.read_until("login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("show slot info\n")
tn.write("exit\n")
string = str(tn.read_all())
print string
for line in string.splitlines():
if line.startswith('Temperature:'):
Temperature = line[34:36]
print Temperature
答案 0 :(得分:0)
可能,您需要从主机上删除换行符; readlines()返回整行,包括任何换行符,因此您需要查找example.com\n
之类的主机。
tn = telnetlib.Telnet(HOST[i].strip())