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'
正規化されたファイルに保存する方法はありますか? only 21.10.176.4.txt?