import telnetlib
import socket
ipfile = "129.9.0.104"
user = "root"
password = "Test1234."
outputfile = ((ipfile)+".output")
f = open(outputfile, 'w')
f.write("")
f.close()
with open(ipfile) as ips:
all_ips = [x.rstrip() for x in ips] # get all ips in a list and strip newline
for ip in all_ips:
try:
tn = telnetlib.Telnet(ip,23,2)
tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(b"screen 0 tem\n")
tn.write(b"display version\n") # print(tn.read_all().decode('ascii'))
with open(outputfile,"ab") as f: #write to a fil
f.write(tn.read_all())
except socket.timeout:
print((ip)+" timeout")


