I using the following code to read a txt file with host addresses, line by line, but when the code create and write to file as log, it writing with quoting marks and '?' character:
The code is this:
import getpass
import sys
import telnetlib
user = "cisco"
password = "cisco"
file = open('hosts.txt', 'r')
for line in file:
tn = telnetlib.Telnet(line)
tn.read_until("Username: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("enable \n")
tn.write(password + "\n")
tn.write("sh ver | i revision \n")
tn.write("exit \n")
str_all = tn.read_all()
log = open(line + ".txt","w")
log.write(str_all)
tn.close()
So the file created is this:
[temp@ser1 Projeto]$ ls
21.10.176.4?.txt clean_up_819 hosts.txt master.py test1.txt teste.txt
Then when I use cat the file is displaing with question marks:
[noctemp@svcactides Projeto_QoS]$ cat '21.10.176.4
.txt'
Is there any way to save in a file normalized called only 21.10.176.4.txt ?