【发布时间】:2018-11-05 22:25:55
【问题描述】:
我一直在尝试编写允许我从远程登录服务器获取文件的代码,如果我们可以在远程登录写入函数中包含变量,我想这样做。
这是我的代码。
import telnetlib
import sys
import getpass
host = "192.168.1.1"
tn = telnetlib.Telnet(host, "23")
tn.write((" \n").encode('ascii'))
tn.write((" \n").encode('ascii'))
tn.write(("terminal length 1000 \n").encode('ascii'))
tn.write(("terminal width 24 \n").encode('ascii'))
tn.write(("""copy command-output "show tech all" tftp 192.168.1.10 test.txt \n""").encode('ascii'))
tn.write(("exit \n").encode('ascii'))
tn.write(("exit \n").encode('ascii'))
tn.write(("y").encode('ascii'))
print (tn.read_all())
这是正在发送的命令,它应该在一个字符串中。
复制命令输出“show tech all”tftp 192.168.1.10 test.txt
我想将它改为 host.txt 而不是 test.txt
比如上面的代码host == 192.168.1.1,那么文件名本质上应该是192.168.1.1.txt,这样可以吗?
【问题讨论】:
-
您可以在任何可以使用字符串(字面量)的地方使用变量(其值为字符串)。你有什么不清楚的地方?
标签: python python-3.x telnet telnetlib