1
다음 코드를 사용하여 호스트 주소가있는 txt 파일을 한 줄씩 읽습니다. 그러나 코드가 로그로 작성하고 파일에 쓰면 따옴표와 '?' 문자 : 나는 파일 물음표 displaing되어 고양이를 사용할 때 다음따옴표를 사용하지 않고 파일에 쓰기
[[email protected] Projeto]$ ls
21.10.176.4?.txt clean_up_819 hosts.txt master.py test1.txt teste.txt
:
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()
그래서 만든 파일이 있습니다 :
코드는 다음입니다
[[email protected] Projeto_QoS]$ cat '21.10.176.4
.txt'
정규화 된 파일에 저장할 방법이 있습니까? 전용 21.10.176.4.txt?