Sep-24-2017, 04:58 PM
I trying connect into different switches using a python script, but I cant read properly the file that contains the ip address of the switches.If someone could help me figure out how I can read this file, I would be glad...Cheers
10.0.0.1
10.0.0.2
10.0.0.4
import sys import telnetlib user ="teste" password ="teste" # here is my problem for line in open('ips.txt'): HOST = line tn = telnetlib.Telnet(HOST) tn.read_until("Username: ") tn.write(user + "\n") tn.read_until("Password: ") tn.write(password + "\n") tn.write("enable\n") tn.write("cisco\n") tn.write(" conf t \n") tn.write("int loop 0 \n") tn.write("int ip add 1.1.1.1 255.255.255.255 \n") tn.write("exit \n") #tn.write(" hostname legal" + str(n) + "\n") print("executado com sucesso")My file looks like this:
10.0.0.1
10.0.0.2
10.0.0.4